You are here

class Dummy in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 tests/modules/geolocation_dummy_geocoder/src/Plugin/geolocation/Geocoder/Dummy.php \Drupal\geolocation_dummy_geocoder\Plugin\geolocation\Geocoder\Dummy
  2. 8 tests/modules/geolocation_dummy_geocoder/src/Plugin/geolocation/Geocoder/Dummy.php \Drupal\geolocation_dummy_geocoder\Plugin\geolocation\Geocoder\Dummy

Provides the Google Geocoding API.

Plugin annotation


@Geocoder(
  id = "dummy",
  name = @Translation("Dummy Geocoder"),
  locationCapable = true,
  boundaryCapable = false,
)

Hierarchy

Expanded class hierarchy of Dummy

1 file declares its use of Dummy
DummyGeocoderController.php in tests/modules/geolocation_dummy_geocoder/src/Controller/DummyGeocoderController.php

File

tests/modules/geolocation_dummy_geocoder/src/Plugin/geolocation/Geocoder/Dummy.php, line 18

Namespace

Drupal\geolocation_dummy_geocoder\Plugin\geolocation\Geocoder
View source
class Dummy extends GeocoderBase {
  public static $targets = [
    'Berlin' => [
      'lat' => 52.517037,
      'lng' => 13.38886,
    ],
    'Vladivostok' => [
      'lat' => 43.115284,
      'lng' => 131.885401,
    ],
    'Santiago de Chile' => [
      'lat' => -33.437913,
      'lng' => -70.65045600000001,
    ],
  ];

  /**
   * {@inheritdoc}
   */
  public function formAttachGeocoder(array &$render_array, $element_name) {
    $render_array['geolocation_geocoder_dummy'] = [
      '#type' => 'textfield',
      '#description' => $this
        ->t('Enter one of the statically defined targets. See geolocation/Geocoder/Dummy.php.'),
      '#attributes' => [
        'class' => [
          'form-autocomplete',
          'geolocation-geocoder-dummy',
        ],
        'data-source-identifier' => $element_name,
      ],
    ];
    $render_array = BubbleableMetadata::mergeAttachments($render_array, [
      '#attached' => [
        'library' => [
          0 => 'geolocation_dummy_geocoder/geocoder',
        ],
      ],
    ]);
    $render_array['geolocation_geocoder_dummy_state'] = [
      '#type' => 'hidden',
      '#default_value' => 1,
      '#attributes' => [
        'class' => [
          'geolocation-geocoder-dummy-state',
        ],
        'data-source-identifier' => $element_name,
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function geocode($address) {
    if (empty($address)) {
      return FALSE;
    }
    if (!empty(self::$targets[$address])) {
      return [
        'location' => [
          'lat' => self::$targets[$address]['lat'],
          'lng' => self::$targets[$address]['lng'],
        ],
        'boundary' => [
          'lat_north_east' => self::$targets[$address]['lat'] + 0.01,
          'lng_north_east' => self::$targets[$address]['lng'] + 0.01,
          'lat_south_west' => self::$targets[$address]['lat'] + 0.01,
          'lng_south_west' => self::$targets[$address]['lng'] + 0.01,
        ],
      ];
    }
    else {
      return FALSE;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
Dummy::$targets public static property
Dummy::formAttachGeocoder public function Attach geocoding logic to input element. Overrides GeocoderBase::formAttachGeocoder
Dummy::geocode public function Geocode an address. Overrides GeocoderBase::geocode
GeocoderBase::$countryFormatterManager protected property Country formatter manager.
GeocoderBase::addressElements protected function Get formatted address elements from atomics.
GeocoderBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
GeocoderBase::getDefaultSettings protected function Return plugin default settings. 2
GeocoderBase::getOptionsForm public function Return additional options form. Overrides GeocoderInterface::getOptionsForm 2
GeocoderBase::getSettings public function Return plugin settings.
GeocoderBase::processOptionsForm public function Process the form built above. Overrides GeocoderInterface::processOptionsForm
GeocoderBase::reverseGeocode public function Reverse geocode an address. Overrides GeocoderInterface::reverseGeocode 2
GeocoderBase::__construct public function GoogleGeocoderBase constructor. Overrides PluginBase::__construct 1
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.