class ProviderPluginManager in Geocoder 8.2
Same name and namespace in other branches
- 8.3 src/ProviderPluginManager.php \Drupal\geocoder\ProviderPluginManager
Provides a plugin manager for geocoder providers.
Hierarchy
- class \Drupal\Component\Plugin\PluginManagerBase implements PluginManagerInterface uses DiscoveryTrait
- class \Drupal\Core\Plugin\DefaultPluginManager implements CachedDiscoveryInterface, PluginManagerInterface, CacheableDependencyInterface uses DiscoveryCachedTrait, UseCacheBackendTrait
- class \Drupal\geocoder\GeocoderPluginManagerBase
- class \Drupal\geocoder\ProviderPluginManager uses StringTranslationTrait
- class \Drupal\geocoder\GeocoderPluginManagerBase
- class \Drupal\Core\Plugin\DefaultPluginManager implements CachedDiscoveryInterface, PluginManagerInterface, CacheableDependencyInterface uses DiscoveryCachedTrait, UseCacheBackendTrait
Expanded class hierarchy of ProviderPluginManager
8 files declare their use of ProviderPluginManager
- AddressGeocodeFormatter.php in modules/
geocoder_address/ src/ Plugin/ Field/ FieldFormatter/ AddressGeocodeFormatter.php - DefaultField.php in modules/
geocoder_field/ src/ Plugin/ Geocoder/ Field/ DefaultField.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
1 string reference to 'ProviderPluginManager'
1 service uses ProviderPluginManager
File
- src/
ProviderPluginManager.php, line 19
Namespace
Drupal\geocoderView source
class ProviderPluginManager extends GeocoderPluginManagerBase {
use StringTranslationTrait;
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $config;
/**
* The Renderer service property.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $renderer;
/**
* The Link generator Service.
*
* @var \Drupal\Core\Utility\LinkGeneratorInterface
*/
protected $link;
/**
* Constructs a new geocoder provider plugin manager.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations,.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* The cache backend to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* A config factory for retrieving required config objects.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
* @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator
* The Link Generator service.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, RendererInterface $renderer, LinkGeneratorInterface $link_generator) {
parent::__construct('Plugin/Geocoder/Provider', $namespaces, $module_handler, ProviderInterface::class, GeocoderProvider::class);
$this
->alterInfo('geocoder_provider_info');
$this
->setCacheBackend($cache_backend, 'geocoder_provider_plugins');
$this->config = $config_factory
->get('geocoder.settings');
$this->stringTranslation = $string_translation;
$this->renderer = $renderer;
$this->link = $link_generator;
}
/**
* Return the array of plugins and their settings if any.
*
* @return array
* A list of plugins with their settings.
*/
public function getPlugins() {
$plugins_arguments = (array) $this->config
->get('plugins_options');
$definitions = array_map(function (array $definition) use ($plugins_arguments) {
$plugins_arguments += [
$definition['id'] => [],
];
$definition += [
'name' => $definition['id'],
'arguments' => [],
];
$definition['arguments'] = array_merge((array) $definition['arguments'], (array) $plugins_arguments[$definition['id']]);
return $definition;
}, $this
->getDefinitions());
ksort($definitions);
return $definitions;
}
/**
* Generates the Draggable Table of Selectable Geocoder Plugins.
*
* @param array $enabled_plugins
* The list of the enabled plugins machine names.
*
* @return array
* The plugins table list.
*/
public function providersPluginsTableList(array $enabled_plugins) {
$geocoder_settings_link = $this->link
->generate(t('Edit options in the Geocoder configuration page</span>'), Url::fromRoute('geocoder.settings', [], [
'query' => [
'destination' => Url::fromRoute('<current>')
->toString(),
],
]));
$options_field_description = [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => $this
->t('Object literals in YAML format. @geocoder_settings_link', [
'@geocoder_settings_link' => $geocoder_settings_link,
]),
'#attributes' => [
'class' => [
'options-field-description',
],
],
];
$caption = [
'title' => [
'#type' => 'html_tag',
'#tag' => 'label',
'#value' => $this
->t('Geocoder plugin(s)'),
],
'caption' => [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => $this
->t('Select the Geocoder plugins to use, you can reorder them. The first one to return a valid value will be used.'),
],
];
$element['plugins'] = [
'#type' => 'table',
'#header' => [
$this
->t('Name'),
$this
->t('Weight'),
$this
->t('Options<br>@options_field_description', [
'@options_field_description' => $this->renderer
->renderRoot($options_field_description),
]),
],
'#tabledrag' => [
[
'action' => 'order',
'relationship' => 'sibling',
'group' => 'plugins-order-weight',
],
],
'#caption' => $this->renderer
->renderRoot($caption),
// We need this class for #states to hide the entire table.
'#attributes' => [
'class' => [
'js-form-item',
'geocode-plugins-list',
],
],
];
// Reorder the plugins promoting the default ones in the proper order.
$plugins = array_combine($enabled_plugins, $enabled_plugins);
foreach ($this
->getPlugins() as $plugin) {
// Non-default values are appended at the end.
$plugins[$plugin['id']] = $plugin;
}
$plugins = array_map(function ($plugin, $weight) use ($enabled_plugins) {
$checked = in_array($plugin['id'], $enabled_plugins);
return array_merge($plugin, [
'checked' => $checked,
'weight' => $checked ? $weight : 0,
'arguments' => empty($plugin['arguments']) ? (string) $this
->t("This plugin doesn't accept arguments.") : Yaml::encode($plugin['arguments']),
]);
}, $plugins, range(0, count($plugins) - 1));
uasort($plugins, function ($pluginA, $pluginB) {
$order = strcmp($pluginB['checked'], $pluginA['checked']);
if (0 === $order) {
$order = $pluginA['weight'] - $pluginB['weight'];
if (0 === $order) {
$order = strcmp($pluginA['name'], $pluginB['name']);
}
}
return $order;
});
foreach ($plugins as $plugin) {
$element['plugins'][$plugin['id']] = [
'checked' => [
'#type' => 'checkbox',
'#title' => $plugin['name'],
'#default_value' => $plugin['checked'],
],
'weight' => [
'#type' => 'weight',
'#title' => $this
->t('Weight for @title', [
'@title' => $plugin['name'],
]),
'#title_display' => 'invisible',
'#default_value' => $plugin['weight'],
'#delta' => 20,
'#attributes' => [
'class' => [
'plugins-order-weight',
],
],
],
'arguments' => [
'#type' => 'html_tag',
'#tag' => 'pre',
'#value' => $plugin['arguments'],
],
'#attributes' => [
'class' => [
'draggable',
],
],
];
}
return $element['plugins'];
}
/**
* Function to lower case keys in a multidimensional array.
*
* @param array $arr
* The input array.
*
* @return array
* The return array
*
* @TODO: This should be removed before the stable release 8.x-2.0.
*/
private function arrayLowerKeyCaseRecursive(array $arr) {
return array_map(function ($item) {
if (is_array($item)) {
$item = $this
->arrayLowerKeyCaseRecursive($item);
}
return $item;
}, array_change_key_case($arr));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultPluginManager:: |
protected | property | Additional namespaces the annotation discovery mechanism should scan for annotation definitions. | |
DefaultPluginManager:: |
protected | property | Name of the alter hook if one should be invoked. | |
DefaultPluginManager:: |
protected | property | The cache key. | |
DefaultPluginManager:: |
protected | property | An array of cache tags to use for the cached definitions. | |
DefaultPluginManager:: |
protected | property | A set of defaults to be referenced by $this->processDefinition() if additional processing of plugins is necessary or helpful for development purposes. | 9 |
DefaultPluginManager:: |
protected | property | The module handler to invoke the alter hook. | 1 |
DefaultPluginManager:: |
protected | property | An object that implements \Traversable which contains the root paths keyed by the corresponding namespace to look for plugin implementations. | |
DefaultPluginManager:: |
protected | property | The name of the annotation that contains the plugin definition. | |
DefaultPluginManager:: |
protected | property | The interface each plugin should implement. | 1 |
DefaultPluginManager:: |
protected | property | The subdirectory within a namespace to look for plugins, or FALSE if the plugins are in the top level of the namespace. | |
DefaultPluginManager:: |
protected | function | Invokes the hook to alter the definitions if the alter hook is set. | 1 |
DefaultPluginManager:: |
protected | function | Sets the alter hook name. | |
DefaultPluginManager:: |
public | function |
Clears static and persistent plugin definition caches. Overrides CachedDiscoveryInterface:: |
5 |
DefaultPluginManager:: |
protected | function | Extracts the provider from a plugin definition. | |
DefaultPluginManager:: |
protected | function | Finds plugin definitions. | 7 |
DefaultPluginManager:: |
private | function | Fix the definitions of context-aware plugins. | |
DefaultPluginManager:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
|
DefaultPluginManager:: |
protected | function | Returns the cached plugin definitions of the decorated discovery class. | |
DefaultPluginManager:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
|
DefaultPluginManager:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
|
DefaultPluginManager:: |
public | function |
Gets the definition of all plugins for this type. Overrides DiscoveryTrait:: |
2 |
DefaultPluginManager:: |
protected | function |
Gets the plugin discovery. Overrides PluginManagerBase:: |
12 |
DefaultPluginManager:: |
protected | function |
Gets the plugin factory. Overrides PluginManagerBase:: |
|
DefaultPluginManager:: |
public | function | Performs extra processing on plugin definitions. | 13 |
DefaultPluginManager:: |
protected | function | Determines if the provider of a definition exists. | 3 |
DefaultPluginManager:: |
public | function | Initialize the cache backend. | |
DefaultPluginManager:: |
protected | function | Sets a cache of plugin definitions for the decorated discovery class. | |
DefaultPluginManager:: |
public | function |
Disable the use of caches. Overrides CachedDiscoveryInterface:: |
1 |
DiscoveryCachedTrait:: |
protected | property | Cached definitions array. | 1 |
DiscoveryCachedTrait:: |
public | function |
Overrides DiscoveryTrait:: |
3 |
DiscoveryTrait:: |
protected | function | Gets a specific plugin definition. | |
DiscoveryTrait:: |
public | function | ||
GeocoderPluginManagerBase:: |
protected | property | List of fields types available as source for Geocode operations. | |
GeocoderPluginManagerBase:: |
protected | property | List of fields types available as source for Reverse Geocode operations. | |
GeocoderPluginManagerBase:: |
public | function | Gets a list of fields types available for Geocode operations. | |
GeocoderPluginManagerBase:: |
public | function | Gets a list of available plugins to be used in forms. | |
GeocoderPluginManagerBase:: |
public | function | Gets a list of fields types available for Reverse Geocode operations. | |
PluginManagerBase:: |
protected | property | The object that discovers plugins managed by this manager. | |
PluginManagerBase:: |
protected | property | The object that instantiates plugins managed by this manager. | |
PluginManagerBase:: |
protected | property | The object that returns the preconfigured plugin instance appropriate for a particular runtime condition. | |
PluginManagerBase:: |
public | function |
Creates a pre-configured instance of a plugin. Overrides FactoryInterface:: |
12 |
PluginManagerBase:: |
public | function |
Gets a preconfigured instance of a plugin. Overrides MapperInterface:: |
7 |
PluginManagerBase:: |
protected | function | Allows plugin managers to specify custom behavior if a plugin is not found. | 1 |
ProviderPluginManager:: |
protected | property | The config factory service. | |
ProviderPluginManager:: |
protected | property | The Link generator Service. | |
ProviderPluginManager:: |
protected | property | The Renderer service property. | |
ProviderPluginManager:: |
private | function | Function to lower case keys in a multidimensional array. | |
ProviderPluginManager:: |
public | function |
Return the array of plugins and their settings if any. Overrides GeocoderPluginManagerBase:: |
|
ProviderPluginManager:: |
public | function | Generates the Draggable Table of Selectable Geocoder Plugins. | |
ProviderPluginManager:: |
public | function |
Constructs a new geocoder provider plugin manager. Overrides DefaultPluginManager:: |
|
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. | |
UseCacheBackendTrait:: |
protected | property | Cache backend instance. | |
UseCacheBackendTrait:: |
protected | property | Flag whether caches should be used or skipped. | |
UseCacheBackendTrait:: |
protected | function | Fetches from the cache backend, respecting the use caches flag. | 1 |
UseCacheBackendTrait:: |
protected | function | Stores data in the persistent cache, respecting the use caches flag. |