abstract class GoogleMapsProviderBase in Geolocation Field 8.3
Same name and namespace in other branches
- 8.2 modules/geolocation_google_maps/src/GoogleMapsProviderBase.php \Drupal\geolocation_google_maps\GoogleMapsProviderBase
Class GoogleMapsProviderBase.
@package Drupal\geolocation_google_maps
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\geolocation\MapProviderBase implements ContainerFactoryPluginInterface, MapProviderInterface
- class \Drupal\geolocation_google_maps\GoogleMapsProviderBase
- class \Drupal\geolocation\MapProviderBase implements ContainerFactoryPluginInterface, MapProviderInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of GoogleMapsProviderBase
3 files declare their use of GoogleMapsProviderBase
- geolocation_google_maps.module in modules/
geolocation_google_maps/ geolocation_google_maps.module - Google Maps hooks.
- GoogleMaps.php in modules/
geolocation_google_maps/ src/ Plugin/ geolocation/ MapProvider/ GoogleMaps.php - GoogleStaticMaps.php in modules/
geolocation_google_maps/ modules/ geolocation_google_static_maps/ src/ Plugin/ geolocation/ MapProvider/ GoogleStaticMaps.php
File
- modules/
geolocation_google_maps/ src/ GoogleMapsProviderBase.php, line 14
Namespace
Drupal\geolocation_google_mapsView source
abstract class GoogleMapsProviderBase extends MapProviderBase {
/**
* Google map style - Roadmap.
*
* @var string
*/
public static $roadmap = 'ROADMAP';
/**
* Google map style - Satellite.
*
* @var string
*/
public static $satellite = 'SATELLITE';
/**
* Google map style - Hybrid.
*
* @var string
*/
public static $hybrid = 'HYBRID';
/**
* Google map style - Terrain.
*
* @var string
*/
public static $terrain = 'TERRAIN';
/**
* Google maps url.
*
* @var string
*/
public static $googleMapsApiUrlBase = 'https://maps.googleapis.com';
/**
* Google maps url from PR China.
*
* @var string
*/
public static $googleMapsApiUrlBaseChina = 'https://maps.google.cn';
/**
* Google maps url from PR China.
*
* @var string
*/
public static $googleMapsApiUrlPath = '/maps/api';
/**
* Return all module and custom defined parameters.
*
* @param array $additional_parameters
* Additional parameters.
*
* @return array
* Parameters
*/
public function getGoogleMapsApiParameters(array $additional_parameters = []) {
$config = \Drupal::config('geolocation_google_maps.settings');
$geolocation_parameters = [
'key' => KeyProvider::getKeyValue($config
->get('google_map_api_key')),
];
$module_parameters = \Drupal::moduleHandler()
->invokeAll('geolocation_google_maps_parameters') ?: [];
$custom_parameters = $config
->get('google_map_custom_url_parameters') ?: [];
// Set the map language to site language if desired and possible.
if ($config
->get('use_current_language') && \Drupal::moduleHandler()
->moduleExists('language')) {
$custom_parameters['language'] = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
}
$parameters = array_replace_recursive($additional_parameters, $custom_parameters, $module_parameters, $geolocation_parameters);
foreach ($parameters as $key => $value) {
if (is_string($value) && $value === '') {
unset($parameters[$key]);
}
}
return $parameters;
}
/**
* Return the fully build URL to load Google Maps API.
*
* @param array $additional_parameters
* Additional parameters.
*
* @return string
* Google Maps API URL
*/
public function getGoogleMapsApiUrl(array $additional_parameters = []) {
$config = \Drupal::config('geolocation_google_maps.settings');
if (!empty($config
->get('google_maps_base_url'))) {
$google_url = $config
->get('google_maps_base_url');
}
elseif ($config
->get('china_mode')) {
$google_url = static::$googleMapsApiUrlBaseChina;
}
else {
$google_url = static::$googleMapsApiUrlBase;
}
$parameters = [];
foreach ($this
->getGoogleMapsApiParameters($additional_parameters) as $parameter => $value) {
$parameters[$parameter] = is_array($value) ? implode(',', $value) : $value;
}
$url = Url::fromUri($google_url . static::$googleMapsApiUrlPath, [
'query' => $parameters,
'https' => TRUE,
]);
return $url
->toString();
}
/**
* An array of all available map types.
*
* @return array
* The map types.
*/
private function getMapTypes() {
$mapTypes = [
static::$roadmap => 'Road map view',
static::$satellite => 'Google Earth satellite images',
static::$hybrid => 'A mixture of normal and satellite views',
static::$terrain => 'A physical map based on terrain information',
];
return array_map([
$this,
't',
], $mapTypes);
}
/**
* {@inheritdoc}
*/
public static function getDefaultSettings() {
return array_replace_recursive(parent::getDefaultSettings(), [
'type' => static::$roadmap,
'zoom' => 10,
'height' => '400px',
'width' => '100%',
]);
}
/**
* {@inheritdoc}
*/
public function getSettings(array $settings) {
$settings = parent::getSettings($settings);
$settings['zoom'] = (int) $settings['zoom'];
return $settings;
}
/**
* {@inheritdoc}
*/
public function getSettingsSummary(array $settings) {
$types = $this
->getMapTypes();
$settings = array_replace_recursive(self::getDefaultSettings(), $settings);
$summary = parent::getSettingsSummary($settings);
$summary[] = $this
->t('Map Type: @type', [
'@type' => $types[$settings['type']],
]);
$summary[] = $this
->t('Zoom level: @zoom', [
'@zoom' => $settings['zoom'],
]);
$summary[] = $this
->t('Height: @height', [
'@height' => $settings['height'],
]);
$summary[] = $this
->t('Width: @width', [
'@width' => $settings['width'],
]);
return $summary;
}
/**
* {@inheritdoc}
*/
public function getSettingsForm(array $settings, array $parents = []) {
$settings = $this
->getSettings($settings);
$parents_string = '';
if ($parents) {
$parents_string = implode('][', $parents) . '][';
}
$form = parent::getSettingsForm($settings, $parents);
/*
* General settings.
*/
$form['general_settings'] = [
'#type' => 'fieldset',
'#title' => $this
->t('General'),
];
$form['height'] = [
'#group' => $parents_string . 'general_settings',
'#type' => 'textfield',
'#title' => $this
->t('Height'),
'#description' => $this
->t('Enter the dimensions and the measurement units. E.g. 200px or 100%.'),
'#size' => 4,
'#default_value' => $settings['height'],
];
$form['width'] = [
'#group' => $parents_string . 'general_settings',
'#type' => 'textfield',
'#title' => $this
->t('Width'),
'#description' => $this
->t('Enter the dimensions and the measurement units. E.g. 200px or 100%.'),
'#size' => 4,
'#default_value' => $settings['width'],
];
$form['type'] = [
'#group' => $parents_string . 'general_settings',
'#type' => 'select',
'#title' => $this
->t('Default map type'),
'#options' => $this
->getMapTypes(),
'#default_value' => $settings['type'],
'#process' => [
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'processGroup',
],
[
'\\Drupal\\Core\\Render\\Element\\Select',
'processSelect',
],
],
'#pre_render' => [
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'preRenderGroup',
],
],
];
$form['zoom'] = [
'#group' => $parents_string . 'general_settings',
'#type' => 'number',
'#title' => $this
->t('Zoom level'),
'#description' => $this
->t('The initial resolution at which to display the map, where zoom 0 corresponds to a map of the Earth fully zoomed out, and higher zoom levels zoom in at a higher resolution up to 20 for streetlevel.'),
'#default_value' => $settings['zoom'],
'#process' => [
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'processGroup',
],
],
'#pre_render' => [
[
'\\Drupal\\Core\\Render\\Element\\Number',
'preRenderNumber',
],
[
'\\Drupal\\Core\\Render\\Element\\RenderElement',
'preRenderGroup',
],
],
];
if ($parents_string) {
$form['zoom']['#group'] = $parents_string . 'general_settings';
}
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 | |
GoogleMapsProviderBase:: |
public static | property | Google maps url. | |
GoogleMapsProviderBase:: |
public static | property | Google maps url from PR China. | |
GoogleMapsProviderBase:: |
public static | property | Google maps url from PR China. | 2 |
GoogleMapsProviderBase:: |
public static | property | Google map style - Hybrid. | |
GoogleMapsProviderBase:: |
public static | property | Google map style - Roadmap. | |
GoogleMapsProviderBase:: |
public static | property | Google map style - Satellite. | |
GoogleMapsProviderBase:: |
public static | property | Google map style - Terrain. | |
GoogleMapsProviderBase:: |
public static | function |
Provide a populated settings array. Overrides MapProviderBase:: |
2 |
GoogleMapsProviderBase:: |
public | function | Return all module and custom defined parameters. | 1 |
GoogleMapsProviderBase:: |
public | function | Return the fully build URL to load Google Maps API. | |
GoogleMapsProviderBase:: |
private | function | An array of all available map types. | |
GoogleMapsProviderBase:: |
public | function |
Provide map provider specific settings ready to handover to JS. Overrides MapProviderBase:: |
1 |
GoogleMapsProviderBase:: |
public | function |
Provide a generic map settings form array. Overrides MapProviderBase:: |
2 |
GoogleMapsProviderBase:: |
public | function |
Provide a summary array to use in field formatters. Overrides MapProviderBase:: |
|
MapProviderBase:: |
protected | property | Map feature manager. | |
MapProviderBase:: |
public | function |
Alter common map build array. Overrides MapProviderInterface:: |
5 |
MapProviderBase:: |
public | function |
Alter render array. Overrides MapProviderInterface:: |
6 |
MapProviderBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
MapProviderBase:: |
public static | function |
Return available control positions. Overrides MapProviderInterface:: |
5 |
MapProviderBase:: |
public | function | Validate form. | |
MapProviderBase:: |
public | function |
Constructs a new GeocoderBase object. Overrides PluginBase:: |
|
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. |