DataProviderManager.php in Geolocation Field 8.2
File
src/DataProviderManager.php
View source
<?php
namespace Drupal\geolocation;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\NestedArray;
class DataProviderManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/geolocation/DataProvider', $namespaces, $module_handler, 'Drupal\\geolocation\\DataProviderInterface', 'Drupal\\geolocation\\Annotation\\DataProvider');
$this
->alterInfo('geolocation_dataprovider_info');
$this
->setCacheBackend($cache_backend, 'geolocation_dataprovider');
}
public function getDataProviderByViewsField(FieldPluginBase $viewField, array $configuration = []) {
$definitions = $this
->getDefinitions();
try {
foreach ($definitions as $dataProviderId => $dataProviderDefinition) {
$dataProvider = $this
->createInstance($dataProviderId, $configuration);
if ($dataProvider
->isViewsGeoOption($viewField)) {
$dataProvider
->setViewsField($viewField);
return $dataProvider;
}
}
} catch (\Exception $e) {
return FALSE;
}
return FALSE;
}
public function getDataProviderByFieldDefinition(FieldDefinitionInterface $fieldDefinition, array $configuration = []) {
$definitions = $this
->getDefinitions();
try {
foreach ($definitions as $dataProviderId => $dataProviderDefinition) {
$dataProvider = $this
->createInstance($dataProviderId, $configuration);
if ($dataProvider
->isFieldGeoOption($fieldDefinition)) {
$dataProvider
->setFieldDefinition($fieldDefinition);
return $dataProvider;
}
}
} catch (\Exception $e) {
return FALSE;
}
return FALSE;
}
public function addDataProviderSettingsFormAjax(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[] = 'data_provider_settings';
return NestedArray::getValue($form, $settings_element_parents);
}
}