Commit 45520e54 authored by bircher's avatar bircher

Issue #2859153: Add possibility to wrap a given storage with filters

parent cb877e62
......@@ -2,6 +2,8 @@
namespace Drupal\config_filter;
use Drupal\Core\Config\StorageInterface;
/**
* Interface ConfigFilterManagerInterface.
*
......@@ -9,6 +11,21 @@ namespace Drupal\config_filter;
*/
interface ConfigFilterManagerInterface {
/**
* Get a decorated storage with filters applied.
*
* @param \Drupal\Core\Config\StorageInterface $storage
* The storage to decorate.
* @param string $storage_name
* The name of the storage, so the correct filters can be applied.
* @param string[] $excluded
* The ids of filters to exclude.
*
* @return \Drupal\config_filter\Config\FilteredStorageInterface
* The decorated storage with the filters applied.
*/
public function getFilteredStorage(StorageInterface $storage, $storage_name, array $excluded = []);
/**
* Returns a ConfigStorage object working with the sync config directory.
*
......
......@@ -5,6 +5,7 @@ namespace Drupal\config_filter\Plugin;
use Drupal\config_filter\Config\FilteredStorage;
use Drupal\config_filter\ConfigFilterManagerInterface;
use Drupal\Core\Config\FileStorageFactory;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
......@@ -32,11 +33,22 @@ class ConfigFilterPluginManager extends DefaultPluginManager implements ConfigFi
$this->setCacheBackend($cache_backend, 'config_filter_plugins');
}
/**
* {@inheritdoc}
*/
public function getFilteredStorage(StorageInterface $storage, $storage_name, array $excluded = []) {
$filters = $this->getFilters($storage_name);
if (!empty($excluded)) {
$filters = array_diff_key($filters, array_combine($excluded, $excluded));
}
return new FilteredStorage($storage, $filters);
}
/**
* {@inheritdoc}
*/
public function getFilteredSyncStorage() {
return new FilteredStorage(FileStorageFactory::getSync(), $this->getFilters('config.storage.sync'));
return $this->getFilteredStorage(FileStorageFactory::getSync(), 'config.storage.sync');
}
/**
......@@ -59,11 +71,12 @@ class ConfigFilterPluginManager extends DefaultPluginManager implements ConfigFi
$filters = [];
foreach ($definitions as $id => $definition) {
if (empty($definition['storages'])) {
// The sync storage is the default.
$definition['storages'] = ['config.storage.sync'];
}
if ($definition['status'] && in_array($storage_name, $definition['storages'])) {
$filters[] = $this->createInstance($id, $definition);
$filters[$id] = $this->createInstance($id, $definition);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment