class Yandex in Geolocation Field 8.2
Same name in this branch
- 8.2 modules/geolocation_yandex/src/Plugin/geolocation/MapProvider/Yandex.php \Drupal\geolocation_yandex\Plugin\geolocation\MapProvider\Yandex
- 8.2 modules/geolocation_yandex/src/Plugin/geolocation/Geocoder/Yandex.php \Drupal\geolocation_yandex\Plugin\geolocation\Geocoder\Yandex
Same name and namespace in other branches
- 8.3 modules/geolocation_yandex/src/Plugin/geolocation/Geocoder/Yandex.php \Drupal\geolocation_yandex\Plugin\geolocation\Geocoder\Yandex
Provides the Yandex.
Plugin annotation
@Geocoder(
id = "yandex",
name = @Translation("Yandex"),
description = @Translation("See https://tech.yandex.com/maps/doc/geocoder/desc/concepts/about-docpage/ for details."),
locationCapable = true,
boundaryCapable = true,
frontendCapable = true,
)
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_yandex\Plugin\geolocation\Geocoder\Yandex implements GeocoderInterface
- class \Drupal\geolocation\GeocoderBase implements ContainerFactoryPluginInterface, GeocoderInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Yandex
File
- modules/
geolocation_yandex/ src/ Plugin/ geolocation/ Geocoder/ Yandex.php, line 24
Namespace
Drupal\geolocation_yandex\Plugin\geolocation\GeocoderView source
class Yandex extends GeocoderBase implements GeocoderInterface {
/**
* {@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'], [
'drupalSettings' => [
'geolocation' => [
'geocoder' => [
$this
->getPluginId() => [],
],
],
],
]);
}
/**
* {@inheritdoc}
*/
public function geocode($address) {
if (empty($address)) {
return FALSE;
}
$config = \Drupal::config('yandex_maps.settings');
$lang = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
$url = Url::fromUri('https://geocode-maps.yandex.ru/1.x/', [
'query' => [
'geocode' => $address,
'format' => 'json',
'apikey' => $config
->get('key'),
'lang' => strtolower($lang) . '_' . strtoupper($lang),
],
]);
try {
$result = Json::decode(\Drupal::httpClient()
->get($url
->toString())
->getBody());
} catch (RequestException $e) {
watchdog_exception('geolocation', $e);
return FALSE;
}
$location = [];
if (empty($result['response']['GeoObjectCollection']['featureMember'][0])) {
return FALSE;
}
else {
$coordinates = explode(' ', $result['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['Point']['pos']);
$location['location'] = [
'lat' => $coordinates[0],
'lng' => $coordinates[1],
];
}
if (!empty($result['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['boundedBy']['Envelope'])) {
$lowerCoordinates = explode(' ', $result['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['boundedBy']['Envelope']['lowerCorner']);
$upperCoordinates = explode(' ', $result['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['boundedBy']['Envelope']['upperCorner']);
$location['boundary'] = [
'lat_north_east' => $upperCoordinates[0],
'lng_north_east' => $upperCoordinates[1],
'lat_south_west' => $lowerCoordinates[0],
'lng_south_west' => $lowerCoordinates[1],
];
}
if (!empty($result['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['description'])) {
$location['address'] = $result['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['description'];
}
return $location;
}
}
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 static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
GeocoderBase:: |
protected | function | Return plugin default settings. | 2 |
GeocoderBase:: |
public | function |
Return additional options form. Overrides GeocoderInterface:: |
2 |
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 |
GeocoderBase:: |
public | function |
GoogleGeocoderBase constructor. Overrides PluginBase:: |
1 |
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. | |
Yandex:: |
public | function |
Attach geocoding logic to input element. Overrides GeocoderBase:: |
|
Yandex:: |
public | function |
Geocode an address. Overrides GeocoderBase:: |