ConfigFilterPluginManager.php in Config Filter 8
File
src/Plugin/ConfigFilterPluginManager.php
View source
<?php
namespace Drupal\config_filter\Plugin;
use Drupal\config_filter\ConfigFilterManagerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
class ConfigFilterPluginManager extends DefaultPluginManager implements ConfigFilterManagerInterface {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/ConfigFilter', $namespaces, $module_handler, 'Drupal\\config_filter\\Plugin\\ConfigFilterInterface', 'Drupal\\config_filter\\Annotation\\ConfigFilter');
$this
->alterInfo('config_filter_info');
$this
->setCacheBackend($cache_backend, 'config_filter_plugins');
}
public function getFiltersForStorages(array $storage_names, array $excluded = []) {
$definitions = $this
->getDefinitions();
$filters = [];
foreach ($definitions as $id => $definition) {
if ($definition['status'] && array_intersect($storage_names, $definition['storages']) && !in_array($id, $excluded)) {
$filters[$id] = $this
->createInstance($id, $definition);
}
}
return $filters;
}
public function getFilterInstance($id) {
$definitions = $this
->getDefinitions();
if (array_key_exists($id, $definitions)) {
return $this
->createInstance($id, $definitions[$id]);
}
return NULL;
}
protected function findDefinitions() {
$definitions = array_map(function ($definition) {
if (empty($definition['storages'])) {
$definition['storages'] = [
'config.storage.sync',
];
}
return $definition;
}, parent::findDefinitions());
uasort($definitions, [
'Drupal\\Component\\Utility\\SortArray',
'sortByWeightElement',
]);
return $definitions;
}
}