diff --git a/src/Config/FilteredStorage.php b/src/Config/FilteredStorage.php index 824f4bb..9417579 100644 --- a/src/Config/FilteredStorage.php +++ b/src/Config/FilteredStorage.php @@ -202,14 +202,23 @@ class FilteredStorage implements FilteredStorageInterface { */ public function createCollection($collection) { $filters = []; - foreach ($this->filters as $filter) { + foreach ($this->filters as $key => $filter) { $filter = $filter->filterCreateCollection($collection); if ($filter) { - $filters[] = $filter; + $filters[$key] = $filter; } } - return new static($this->storage->createCollection($collection), $filters); + $storage = $this->storage->createCollection($collection); + $filtered = new static($storage, $filters); + + // Set the storage to all the filters. + foreach ($filters as $filter) { + $filter->setSourceStorage(new ReadOnlyStorage($storage)); + $filter->setFilteredStorage($filtered); + } + + return $filtered; } /** diff --git a/src/Config/StorageFilterInterface.php b/src/Config/StorageFilterInterface.php index e1154e6..ad2c38e 100644 --- a/src/Config/StorageFilterInterface.php +++ b/src/Config/StorageFilterInterface.php @@ -189,7 +189,8 @@ interface StorageFilterInterface { * * @return \Drupal\config_filter\Config\StorageFilterInterface|null * Return a filter that should participate in the collection. This allows - * filters to act on different collections. + * filters to act on different collections. Note that a new instance of the + * filter should be created rather than returning $this directly. */ public function filterCreateCollection($collection); diff --git a/src/Plugin/ConfigFilterBase.php b/src/Plugin/ConfigFilterBase.php index 48d3975..c52133c 100644 --- a/src/Plugin/ConfigFilterBase.php +++ b/src/Plugin/ConfigFilterBase.php @@ -125,7 +125,7 @@ abstract class ConfigFilterBase extends PluginBase implements ConfigFilterInterf * {@inheritdoc} */ public function filterCreateCollection($collection) { - return $this; + return clone $this; } /**