abstract class GoogleGeocoderBase in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 modules/geolocation_google_maps/src/GoogleGeocoderBase.php \Drupal\geolocation_google_maps\GoogleGeocoderBase
Base class.
@package Drupal\geolocation_google_places_api
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\geolocation\GeocoderBase implements ContainerFactoryPluginInterface, GeocoderInterface
- class \Drupal\geolocation_google_maps\GoogleGeocoderBase implements GeocoderInterface
- class \Drupal\geolocation\GeocoderBase implements ContainerFactoryPluginInterface, GeocoderInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of GoogleGeocoderBase
2 files declare their use of GoogleGeocoderBase
- GoogleGeocodingAPI.php in modules/
geolocation_google_maps/ src/ Plugin/ geolocation/ Geocoder/ GoogleGeocodingAPI.php - GooglePlacesAPI.php in modules/
geolocation_google_maps/ modules/ geolocation_google_places_api/ src/ Plugin/ geolocation/ Geocoder/ GooglePlacesAPI.php
File
- modules/
geolocation_google_maps/ src/ GoogleGeocoderBase.php, line 17
Namespace
Drupal\geolocation_google_mapsView source
abstract class GoogleGeocoderBase extends GeocoderBase implements GeocoderInterface {
/**
* Google maps provider.
*
* @var \Drupal\geolocation_google_maps\Plugin\geolocation\MapProvider\GoogleMaps
*/
protected $googleMapsProvider;
/**
* GoogleGeocoderBase constructor.
*
* @param array $configuration
* Configuration.
* @param string $plugin_id
* Plugin ID.
* @param mixed $plugin_definition
* Plugin definition.
* @param \Drupal\geolocation\GeocoderCountryFormattingManager $geocoder_country_formatter_manager
* Country formatter manager.
* @param \Drupal\geolocation\MapProviderManager $map_provider_manager
* Map provider management.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, GeocoderCountryFormattingManager $geocoder_country_formatter_manager, MapProviderManager $map_provider_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $geocoder_country_formatter_manager);
$this->googleMapsProvider = $map_provider_manager
->getMapProvider('google_maps');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('plugin.manager.geolocation.geocoder_country_formatting'), $container
->get('plugin.manager.geolocation.mapprovider'));
}
/**
* {@inheritdoc}
*/
protected function getDefaultSettings() {
$default_settings = parent::getDefaultSettings();
$default_settings['component_restrictions'] = [
'route' => '',
'locality' => '',
'administrative_area' => '',
'postal_code' => '',
'country' => '',
];
$default_settings['boundary_restriction'] = [
'south' => '',
'west' => '',
'north' => '',
'east' => '',
];
return $default_settings;
}
/**
* {@inheritdoc}
*/
public function formAttachGeocoder(array &$render_array, $element_name) {
parent::formAttachGeocoder($render_array, $element_name);
$render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
'library' => [
'geolocation_google_maps/googlemapsapi',
'geolocation_google_maps/google',
],
]);
if (!empty($this->configuration['component_restrictions'])) {
foreach ($this->configuration['component_restrictions'] as $component => $restriction) {
if (empty($restriction)) {
continue;
}
switch ($component) {
case 'administrative_area':
$component = 'administrativeArea';
break;
case 'postal_code':
$component = 'postalCode';
break;
}
$render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
'drupalSettings' => [
'geolocation' => [
'geocoder' => [
$this
->getPluginId() => [
'componentRestrictions' => [
$component => $restriction,
],
],
],
],
],
]);
}
}
if (!empty($this->configuration['boundary_restriction'])) {
$bounds = [];
foreach ($this->configuration['boundary_restriction'] as $key => $value) {
if (empty($value)) {
return;
}
$bounds[$key] = (double) $value;
}
if (!empty($bounds)) {
$render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
'drupalSettings' => [
'geolocation' => [
'geocoder' => [
$this
->getPluginId() => [
'bounds' => $bounds,
],
],
],
],
]);
}
}
}
/**
* {@inheritdoc}
*/
public function getOptionsForm() {
$settings = $this
->getSettings();
$form = parent::getOptionsForm();
$form += [
'component_restrictions' => [
'#type' => 'fieldset',
'#title' => $this
->t('Component Restrictions'),
'#description' => $this
->t('See <a href="https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering">Component Filtering</a>'),
'route' => [
'#type' => 'textfield',
'#default_value' => $settings['component_restrictions']['route'],
'#title' => $this
->t('Route'),
'#size' => 15,
],
'locality' => [
'#type' => 'textfield',
'#default_value' => $settings['component_restrictions']['locality'],
'#title' => $this
->t('Locality'),
'#size' => 15,
],
'administrative_area' => [
'#type' => 'textfield',
'#default_value' => $settings['component_restrictions']['administrative_area'],
'#title' => $this
->t('Administrative Area'),
'#size' => 15,
],
'postal_code' => [
'#type' => 'textfield',
'#default_value' => $settings['component_restrictions']['postal_code'],
'#title' => $this
->t('Postal code'),
'#size' => 5,
],
'country' => [
'#type' => 'textfield',
'#default_value' => $settings['component_restrictions']['country'],
'#title' => $this
->t('Country'),
'#size' => 5,
],
],
'boundary_restriction' => [
'#type' => 'fieldset',
'#title' => $this
->t('Boundary Restriction'),
'#description' => $this
->t('See <a href="https://developers.google.com/maps/documentation/geocoding/intro#Viewports">Viewports</a>'),
'south' => [
'#type' => 'textfield',
'#default_value' => $settings['boundary_restriction']['south'],
'#title' => $this
->t('South'),
'#size' => 15,
],
'west' => [
'#type' => 'textfield',
'#default_value' => $settings['boundary_restriction']['west'],
'#title' => $this
->t('West'),
'#size' => 15,
],
'north' => [
'#type' => 'textfield',
'#default_value' => $settings['boundary_restriction']['north'],
'#title' => $this
->t('North'),
'#size' => 15,
],
'east' => [
'#type' => 'textfield',
'#default_value' => $settings['boundary_restriction']['east'],
'#title' => $this
->t('East'),
'#size' => 15,
],
],
];
return $form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
GeocoderBase:: |
protected | property | Country formatter manager. | |
GeocoderBase:: |
protected | function | Get formatted address elements from atomics. | |
GeocoderBase:: |
public | function |
Geocode an address. Overrides GeocoderInterface:: |
6 |
GeocoderBase:: |
public | function | Return plugin settings. | |
GeocoderBase:: |
public | function |
Process the form built above. Overrides GeocoderInterface:: |
|
GeocoderBase:: |
public | function |
Reverse geocode an address. Overrides GeocoderInterface:: |
2 |
GoogleGeocoderBase:: |
protected | property | Google maps provider. | |
GoogleGeocoderBase:: |
public static | function |
Creates an instance of the plugin. Overrides GeocoderBase:: |
|
GoogleGeocoderBase:: |
public | function |
Attach geocoding logic to input element. Overrides GeocoderBase:: |
2 |
GoogleGeocoderBase:: |
protected | function |
Return plugin default settings. Overrides GeocoderBase:: |
|
GoogleGeocoderBase:: |
public | function |
Return additional options form. Overrides GeocoderBase:: |
|
GoogleGeocoderBase:: |
public | function |
GoogleGeocoderBase constructor. Overrides GeocoderBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |