MapProviderManager.php in Geolocation Field 8.2
File
src/MapProviderManager.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 MapProviderManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/geolocation/MapProvider', $namespaces, $module_handler, 'Drupal\\geolocation\\MapProviderInterface', 'Drupal\\geolocation\\Annotation\\MapProvider');
$this
->alterInfo('geolocation_mapprovider_info');
$this
->setCacheBackend($cache_backend, 'geolocation_mapprovider');
}
public function getMapProvider($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 function getMapProviderDefaultSettings($id) {
$definitions = $this
->getDefinitions();
if (empty($definitions[$id])) {
return FALSE;
}
$classname = $definitions[$id]['class'];
return $classname::getDefaultSettings();
}
public function getMapProviderOptions() {
$options = [];
foreach ($this
->getDefinitions() as $id => $definition) {
$options[$id] = $definition['name'];
}
return $options;
}
public static function addSettingsFormAjax(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[] = 'map_provider_settings';
return NestedArray::getValue($form, $settings_element_parents);
}
}