class Geocoder in Geocoder 8.2
Same name and namespace in other branches
- 8.3 src/Geocoder.php \Drupal\geocoder\Geocoder
- 7.2 src/Geocoder.php \Drupal\geocoder\Geocoder
Provides a geocoder factory class.
Hierarchy
- class \Drupal\geocoder\Geocoder implements GeocoderInterface
Expanded class hierarchy of Geocoder
7 files declare their use of Geocoder
- AddressGeocodeFormatter.php in modules/
geocoder_address/ src/ Plugin/ Field/ FieldFormatter/ AddressGeocodeFormatter.php - FileGeocodeFormatter.php in modules/
geocoder_field/ src/ Plugin/ Field/ FieldFormatter/ FileGeocodeFormatter.php - GeocodeFormatterBase.php in modules/
geocoder_field/ src/ Plugin/ Field/ GeocodeFormatterBase.php - GeocodeOrigin.php in src/
Plugin/ GeofieldProximitySource/ GeocodeOrigin.php - GeocodeOriginAutocomplete.php in src/
Plugin/ GeofieldProximitySource/ deprecated/ GeocodeOriginAutocomplete.php
2 string references to 'Geocoder'
1 service uses Geocoder
File
- src/
Geocoder.php, line 11
Namespace
Drupal\geocoderView source
class Geocoder implements GeocoderInterface {
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $config;
/**
* The geocoder provider plugin manager service.
*
* @var \Drupal\geocoder\ProviderPluginManager
*/
protected $providerPluginManager;
/**
* Constructs a geocoder factory class.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* A config factory for retrieving required config objects.
* @param \Drupal\geocoder\ProviderPluginManager $provider_plugin_manager
* The geocoder provider plugin manager service.
*/
public function __construct(ConfigFactoryInterface $config_factory, ProviderPluginManager $provider_plugin_manager) {
$this->config = $config_factory
->get('geocoder.settings');
$this->providerPluginManager = $provider_plugin_manager;
}
/**
* {@inheritdoc}
*/
public function geocode($data, array $plugins, array $options = []) {
// Retrieve plugins options from the module configurations.
$plugins_options = $this->config
->get('plugins_options') ?: [];
// Merge possible options overrides into plugins options.
$plugins_options = NestedArray::mergeDeep($plugins_options, $options);
foreach ($plugins as $plugin_id) {
// Transform in empty array a null value for the plugin id options.
$plugins_options += [
$plugin_id => [],
];
try {
$provider = $this->providerPluginManager
->createInstance($plugin_id, $plugins_options[$plugin_id]);
return $provider
->geocode($data);
} catch (\Exception $e) {
static::log($e
->getMessage());
}
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function reverse($latitude, $longitude, array $plugins, array $options = []) {
// Retrieve plugins options from the module configurations.
$plugins_options = $this->config
->get('plugins_options');
// Merge possible options overrides into plugins options.
$plugins_options = NestedArray::mergeDeep($plugins_options, $options);
foreach ($plugins as $plugin_id) {
// Transform in empty array a null value for the plugin id options.
$plugins_options += [
$plugin_id => [],
];
try {
$provider = $this->providerPluginManager
->createInstance($plugin_id, $plugins_options[$plugin_id]);
return $provider
->reverse($latitude, $longitude);
} catch (\Exception $e) {
static::log($e
->getMessage());
}
}
return FALSE;
}
/**
* Log a message in the Drupal watchdog and on screen.
*
* @param string $message
* The message.
*/
public static function log($message) {
\Drupal::logger('geocoder')
->warning($message);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Geocoder:: |
protected | property | The config factory service. | |
Geocoder:: |
protected | property | The geocoder provider plugin manager service. | |
Geocoder:: |
public | function |
Geocodes a string. Overrides GeocoderInterface:: |
|
Geocoder:: |
public static | function | Log a message in the Drupal watchdog and on screen. | |
Geocoder:: |
public | function |
Reverse geocode coordinates. Overrides GeocoderInterface:: |
|
Geocoder:: |
public | function | Constructs a geocoder factory class. |