You are here

geolocation.module in Geolocation Field 8.3

Defines a simple geolocation field type.

File

geolocation.module
View source
<?php

/**
 * @file
 * Defines a simple geolocation field type.
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\geolocation\Plugin\migrate\field\Location;

/**
 * Implements hook_help().
 */
function geolocation_help($route_name, RouteMatchInterface $route_match) {
  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',
        ]),
        ':field_ui' => Url::fromRoute('help.page', [
          'name' => 'field_ui',
        ]),
      ]) . '</p>';
      return $output;
  }
  return NULL;
}

/**
 * Implements hook_theme().
 */
function geolocation_theme() {
  return [
    'geolocation_map_wrapper' => [
      'variables' => [
        'attributes' => NULL,
        'maptype' => NULL,
        'locations' => NULL,
        'centre' => NULL,
        'id' => NULL,
        'children' => NULL,
        'controls' => NULL,
        'context' => NULL,
      ],
    ],
    'geolocation_map_location' => [
      'variables' => [
        'attributes' => NULL,
        'children' => NULL,
        'title' => NULL,
        'coordinates' => NULL,
        'id' => NULL,
        'hidden' => NULL,
        'icon' => NULL,
        'label' => NULL,
      ],
    ],
    'geolocation_map_polyline' => [
      'variables' => [
        'attributes' => NULL,
        'children' => NULL,
        'title' => NULL,
        'coordinates' => NULL,
        'stroke_color' => NULL,
        'stroke_width' => NULL,
        'stroke_opacity' => NULL,
      ],
    ],
    'geolocation_map_polygon' => [
      'variables' => [
        'attributes' => NULL,
        'children' => NULL,
        'title' => NULL,
        'coordinates' => 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().
 */
function geolocation_migrate_field_info_alter(&$definitions) {

  // 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',
  ];
}

Functions

Namesort descending Description
geolocation_help Implements hook_help().
geolocation_migrate_field_info_alter Implements hook_migrate_field_info_alter().
geolocation_theme Implements hook_theme().