geolocation-8.x-3.x-dev/src/Hook/Geolocation.php
src/Hook/Geolocation.php
<?php
namespace Drupal\geolocation\Hook;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\geolocation\Plugin\migrate\field\Location;
/**
* Hook implementations for geolocation module core functionality.
*/
class Geolocation {
/**
* Implements hook_help().
*/
#[Hook('help')]
public function help(string $route_name, RouteMatchInterface $route_match): ?string {
switch ($route_name) {
case 'help.page.geolocation':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>'
. t('The Geolocation module allows you to create fields that contain geographical locations.
See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a>
pages for general information on fields and how to create and manage them.',
[
':field' => Url::fromRoute('help.page', ['name' => 'field'])->toString(),
':field_ui' => Url::fromRoute('help.page', ['name' => 'field_ui'])->toString(),
]
)
. '</p>';
return $output;
}
return NULL;
}
/**
* Implements hook_theme().
*/
#[Hook('theme')]
public function theme(): array {
return [
'geolocation_map_wrapper' => [
'variables' => [
'attributes' => NULL,
'maptype' => NULL,
'centre' => NULL,
'id' => NULL,
'layers' => NULL,
'children' => NULL,
'controls' => NULL,
'context' => NULL,
],
],
'geolocation_map_layer' => [
'variables' => [
'attributes' => NULL,
'title' => NULL,
'id' => NULL,
'children' => NULL,
],
],
'geolocation_map_location' => [
'variables' => [
'attributes' => NULL,
'children' => NULL,
'title' => NULL,
'coordinates' => NULL,
'id' => NULL,
'hidden' => NULL,
'icon' => NULL,
'label' => NULL,
'row' => NULL,
],
],
'geolocation_map_shape' => [
'variables' => [
'attributes' => NULL,
'children' => NULL,
'title' => NULL,
'geometry' => NULL,
'geometry_type' => NULL,
'stroke_color' => NULL,
'stroke_width' => NULL,
'stroke_opacity' => NULL,
'fill_color' => NULL,
'fill_opacity' => NULL,
],
],
'geolocation_latlng_formatter' => [
'variables' => [
'lat' => NULL,
'lng' => NULL,
],
'template' => 'geolocation-latlng-formatter',
],
'geolocation_sexagesimal_formatter' => [
'variables' => [
'lat' => NULL,
'lng' => NULL,
],
'template' => 'geolocation-sexagesimal-formatter',
],
];
}
/**
* Implements hook_migrate_field_info_alter().
*/
#[Hook('migrate_field_info_alter')]
public function migrateFieldInfoAlter(array &$definitions): void {
// Defines the location-to-geolocation migrate field plugin.
// This code also wants to replace the location-to-address migrate field
// plugin of Address module: a geolocation with latitude and longitude is
// way more accurate than a (partial) postal address.
if (\Drupal::moduleHandler()->moduleExists('geolocation_address')) {
return;
}
$definitions['location'] = [
'type_map' => [
'location' => 'geolocation',
],
'weight' => 0,
'id' => 'location',
'core' => [7],
'source_module' => 'location_cck',
'destination_module' => 'geolocation',
'class' => Location::class,
'provider' => 'geolocation',
];
}
}
