GeocoderManager.php in Geolocation Field 8.3
File
src/GeocoderManager.php
View source
<?php
namespace Drupal\geolocation;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\NestedArray;
class GeocoderManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/geolocation/Geocoder', $namespaces, $module_handler, 'Drupal\\geolocation\\GeocoderInterface', 'Drupal\\geolocation\\Annotation\\Geocoder');
$this
->alterInfo('geolocation_geocoder_info');
$this
->setCacheBackend($cache_backend, 'geolocation_geocoder');
}
public function getGeocoder($id, array $configuration = []) {
if (!$this
->hasDefinition($id)) {
return FALSE;
}
try {
$instance = $this
->createInstance($id, $configuration);
if ($instance) {
return $instance;
}
} catch (\Exception $e) {
return FALSE;
}
return FALSE;
}
public static function addGeocoderSettingsFormAjax(array $form, FormStateInterface $form_state) {
$triggering_element_parents = $form_state
->getTriggeringElement()['#array_parents'];
$settings_element_parents = $triggering_element_parents;
array_pop($settings_element_parents);
$settings_element_parents[] = 'settings';
return NestedArray::getValue($form, $settings_element_parents);
}
}