updated contrib modules : migrate_tools, migrate_plus, piwik -> matomo, color_field, config_filter, admin_toolbar
This commit is contained in:
@@ -4,8 +4,8 @@ description: Config Filter allows other modules to interact with a ConfigStorage
|
||||
# core: 8.x
|
||||
package: Config
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-27
|
||||
version: '8.x-1.1'
|
||||
# Information added by Drupal.org packaging script on 2018-04-05
|
||||
version: '8.x-1.2'
|
||||
core: '8.x'
|
||||
project: 'config_filter'
|
||||
datestamp: 1511779987
|
||||
datestamp: 1522943894
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Drupal\config_filter\Config;
|
||||
|
||||
use Drupal\config_filter\Exception\InvalidStorageFilterException;
|
||||
use Drupal\Core\Config\StorageInterface;
|
||||
|
||||
/**
|
||||
@@ -43,6 +44,9 @@ class FilteredStorage implements FilteredStorageInterface {
|
||||
|
||||
// Set the storage to all the filters.
|
||||
foreach ($this->filters as $filter) {
|
||||
if (!$filter instanceof StorageFilterInterface) {
|
||||
throw new InvalidStorageFilterException();
|
||||
}
|
||||
$filter->setSourceStorage(new ReadOnlyStorage($storage));
|
||||
$filter->setFilteredStorage($this);
|
||||
}
|
||||
@@ -209,16 +213,7 @@ class FilteredStorage implements FilteredStorageInterface {
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
return new static($this->storage->createCollection($collection), $filters);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\config_filter\Config;
|
||||
|
||||
use Drupal\Core\Config\StorageInterface;
|
||||
|
||||
/**
|
||||
* Class GhostStorage.
|
||||
*
|
||||
* A GhostStorage acts like the normal Storage it wraps. All reading operations
|
||||
* return the values of the decorated storage but write operations are silently
|
||||
* ignored and the ghost pretends that the operation was successful.
|
||||
*
|
||||
* @package Drupal\config_filter\Config
|
||||
*/
|
||||
class GhostStorage extends ReadOnlyStorage implements StorageInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($name, array $data) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($name) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rename($name, $new_name) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteAll($prefix = '') {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\config_filter\Config;
|
||||
|
||||
use Drupal\Core\Config\StorageInterface;
|
||||
|
||||
/**
|
||||
* Trait TransparentStorageFilterTrait.
|
||||
*
|
||||
* Use this trait or ConfigFilterBase to implement a config storage filter.
|
||||
* Filters do not need to be plugins but it is probably the most convenient way
|
||||
* to create them. Use this trait to ensure compatibility in case the interface
|
||||
* ever needs to change for some reason.
|
||||
*
|
||||
* @package Drupal\config_filter\Config
|
||||
*/
|
||||
trait TransparentStorageFilterTrait {
|
||||
|
||||
/**
|
||||
* The read-only source storage on which the filter operations are performed.
|
||||
*
|
||||
* @var \Drupal\Core\Config\StorageInterface
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* The wrapped storage which calls the filter.
|
||||
*
|
||||
* @var \Drupal\Core\Config\StorageInterface
|
||||
*/
|
||||
protected $filtered;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSourceStorage(StorageInterface $storage) {
|
||||
$this->source = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setFilteredStorage(StorageInterface $storage) {
|
||||
$this->filtered = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the read-only source Storage.
|
||||
*
|
||||
* @return \Drupal\Core\Config\StorageInterface
|
||||
* The source storage.
|
||||
*/
|
||||
protected function getSourceStorage() {
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the decorator storage which applies the filters.
|
||||
*
|
||||
* @return \Drupal\Core\Config\StorageInterface
|
||||
* The filtered decorator storage.
|
||||
*/
|
||||
protected function getFilteredStorage() {
|
||||
return $this->filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterRead($name, $data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterWrite($name, array $data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterWriteEmptyIsDelete($name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterExists($name, $exists) {
|
||||
return $exists;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterDelete($name, $delete) {
|
||||
return $delete;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterReadMultiple(array $names, array $data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterRename($name, $new_name, $rename) {
|
||||
return $rename;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterListAll($prefix, array $data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterDeleteAll($prefix, $delete) {
|
||||
return $delete;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterCreateCollection($collection) {
|
||||
return clone $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterGetAllCollectionNames(array $collections) {
|
||||
return $collections;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterGetCollectionName($collection) {
|
||||
return $collection;
|
||||
}
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\config_filter\Exception;
|
||||
|
||||
use Drupal\config_filter\Config\StorageFilterInterface;
|
||||
|
||||
/**
|
||||
* Thrown when a StorageFilterInterface is expected but not present.
|
||||
*/
|
||||
class InvalidStorageFilterException extends \InvalidArgumentException {
|
||||
|
||||
/**
|
||||
* InvalidStorageFilterException constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct("An argument does not implement " . StorageFilterInterface::class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,143 +3,13 @@
|
||||
namespace Drupal\config_filter\Plugin;
|
||||
|
||||
use Drupal\Component\Plugin\PluginBase;
|
||||
use Drupal\Core\Config\StorageInterface;
|
||||
use Drupal\config_filter\Config\TransparentStorageFilterTrait;
|
||||
|
||||
/**
|
||||
* Base class for Config filter plugin plugins.
|
||||
*/
|
||||
abstract class ConfigFilterBase extends PluginBase implements ConfigFilterInterface {
|
||||
|
||||
/**
|
||||
* The read-only source storage on which the filter operations are performed.
|
||||
*
|
||||
* @var \Drupal\Core\Config\StorageInterface
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* The wrapped storage which calls the filter.
|
||||
*
|
||||
* @var \Drupal\Core\Config\StorageInterface
|
||||
*/
|
||||
protected $filtered;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSourceStorage(StorageInterface $storage) {
|
||||
$this->source = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setFilteredStorage(StorageInterface $storage) {
|
||||
$this->filtered = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the read-only source Storage.
|
||||
*
|
||||
* @return \Drupal\Core\Config\StorageInterface
|
||||
* The source storage.
|
||||
*/
|
||||
protected function getSourceStorage() {
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the decorator storage which applies the filters.
|
||||
*
|
||||
* @return \Drupal\Core\Config\StorageInterface
|
||||
* The filtered decorator storage.
|
||||
*/
|
||||
protected function getFilteredStorage() {
|
||||
return $this->filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterRead($name, $data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterWrite($name, array $data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterWriteEmptyIsDelete($name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterExists($name, $exists) {
|
||||
return $exists;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterDelete($name, $delete) {
|
||||
return $delete;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterReadMultiple(array $names, array $data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterRename($name, $new_name, $rename) {
|
||||
return $rename;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterListAll($prefix, array $data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterDeleteAll($prefix, $delete) {
|
||||
return $delete;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterCreateCollection($collection) {
|
||||
return clone $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterGetAllCollectionNames(array $collections) {
|
||||
return $collections;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filterGetCollectionName($collection) {
|
||||
return $collection;
|
||||
}
|
||||
use TransparentStorageFilterTrait;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
namespace Drupal\config_filter\Tests;
|
||||
|
||||
use Drupal\config_filter\Config\FilteredStorage;
|
||||
use Drupal\config_filter\Config\FilteredStorageInterface;
|
||||
use Drupal\config_filter\Config\ReadOnlyStorage;
|
||||
use Drupal\config_filter\Config\StorageFilterInterface;
|
||||
use Drupal\config_filter\Exception\InvalidStorageFilterException;
|
||||
use Drupal\Core\Config\CachedStorage;
|
||||
use Drupal\Core\Config\StorageInterface;
|
||||
use Drupal\KernelTests\Core\Config\Storage\CachedStorageTest;
|
||||
@@ -31,12 +33,8 @@ class FilteredStorageTest extends CachedStorageTest {
|
||||
* Test that the storage is set on the filters.
|
||||
*/
|
||||
public function testSettingStorages() {
|
||||
$filterReflection = new \ReflectionClass(FilteredStorage::class);
|
||||
$filtersProperty = $filterReflection->getProperty('filters');
|
||||
$filtersProperty->setAccessible(TRUE);
|
||||
|
||||
/** @var \Drupal\config_filter\Tests\TransparentFilter[] $filters */
|
||||
$filters = $filtersProperty->getValue($this->storage);
|
||||
$filters = static::getProtectedFilters($this->storage);
|
||||
foreach ($filters as $filter) {
|
||||
// Test that the source storage is a ReadonlyStorage and wraps the cached
|
||||
// storage from the inherited test.
|
||||
@@ -53,6 +51,69 @@ class FilteredStorageTest extends CachedStorageTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that creating collections keeps filters set to the correct storages.
|
||||
*/
|
||||
public function testCollectionStorages() {
|
||||
$collection = $this->randomString();
|
||||
|
||||
// The storage is in its default state.
|
||||
$this->assertEquals(StorageInterface::DEFAULT_COLLECTION, $this->storage->getCollectionName());
|
||||
|
||||
/** @var \Drupal\config_filter\Tests\TransparentFilter[] $filters */
|
||||
$filters = static::getProtectedFilters($this->storage);
|
||||
foreach ($filters as $filter) {
|
||||
// Test that the filters have the correct storage set.
|
||||
$this->assertEquals($this->storage, $filter->getPrivateFilteredStorage());
|
||||
$this->assertEquals(StorageInterface::DEFAULT_COLLECTION, $filter->getPrivateSourceStorage()->getCollectionName());
|
||||
}
|
||||
|
||||
// Create a collection which creates a clone of the storage and filters.
|
||||
$collectionStorage = $this->storage->createCollection($collection);
|
||||
$this->assertInstanceOf(FilteredStorageInterface::class, $collectionStorage);
|
||||
|
||||
/** @var \Drupal\config_filter\Tests\TransparentFilter[] $collectionFilters */
|
||||
$collectionFilters = static::getProtectedFilters($collectionStorage);
|
||||
foreach ($collectionFilters as $filter) {
|
||||
// Test that the cloned filter has the correct storage set.
|
||||
$this->assertEquals($collectionStorage, $filter->getPrivateFilteredStorage());
|
||||
$this->assertEquals($collection, $filter->getPrivateSourceStorage()->getCollectionName());
|
||||
}
|
||||
|
||||
/** @var \Drupal\config_filter\Tests\TransparentFilter[] $filters */
|
||||
$filters = static::getProtectedFilters($this->storage);
|
||||
foreach ($filters as $filter) {
|
||||
// Test that the filters on the original storage are still correctly set.
|
||||
$this->assertEquals($this->storage, $filter->getPrivateFilteredStorage());
|
||||
$this->assertEquals(StorageInterface::DEFAULT_COLLECTION, $filter->getPrivateSourceStorage()->getCollectionName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setting up filters in FilteredStorage::createCollection().
|
||||
*/
|
||||
public function testCreateCollectionFilter() {
|
||||
$collection = $this->randomString();
|
||||
$filteredCollection = $this->randomString();
|
||||
|
||||
$filter = $this->prophesizeFilter();
|
||||
$filterC = $this->prophesizeFilter();
|
||||
$filterC->filterGetCollectionName($collection)->willReturn($filteredCollection);
|
||||
$filter->filterCreateCollection($collection)->willReturn($filterC->reveal());
|
||||
|
||||
$source = $this->prophesize(StorageInterface::class);
|
||||
$sourceC = $this->prophesize(StorageInterface::class);
|
||||
$sourceC->getCollectionName()->willReturn($collection);
|
||||
$source->createCollection($collection)->willReturn($sourceC->reveal());
|
||||
|
||||
$storage = new FilteredStorage($source->reveal(), [$filter->reveal()]);
|
||||
// Creating a collection makes sure the filters were correctly set up.
|
||||
$storageC = $storage->createCollection($collection);
|
||||
|
||||
// Test that the collection is filtered in the collection storage.
|
||||
$this->assertEquals($filteredCollection, $storageC->getCollectionName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the read methods invokes the correct filter methods.
|
||||
*
|
||||
@@ -278,6 +339,23 @@ class FilteredStorageTest extends CachedStorageTest {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an exception is thrown when invalid arguments are passed.
|
||||
*/
|
||||
public function testInvalidStorageFilterArgument() {
|
||||
$source = $this->prophesize(StorageInterface::class);
|
||||
|
||||
// We would do this with $this->expectException but alas drupal is stuck on
|
||||
// phpunit 4 and we try not to add deprecated code.
|
||||
try {
|
||||
new FilteredStorage($source->reveal(), [new \stdClass()]);
|
||||
$this->fail('An exception should have been thrown.');
|
||||
}
|
||||
catch (InvalidStorageFilterException $exception) {
|
||||
$this->assertTrue(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prophesize a StorageFilter.
|
||||
*/
|
||||
@@ -288,6 +366,23 @@ class FilteredStorageTest extends CachedStorageTest {
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filters from a FilteredStorageInterface.
|
||||
*
|
||||
* @param \Drupal\Core\Config\StorageInterface $storage
|
||||
* The storage with the protected filters property.
|
||||
*
|
||||
* @return \Drupal\config_filter\Config\StorageFilterInterface[]
|
||||
* The array of filters.
|
||||
*/
|
||||
protected static function getProtectedFilters(StorageInterface $storage) {
|
||||
$filterReflection = new \ReflectionClass(FilteredStorage::class);
|
||||
$filtersProperty = $filterReflection->getProperty('filters');
|
||||
$filtersProperty->setAccessible(TRUE);
|
||||
|
||||
return $filtersProperty->getValue($storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a random array.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\config_filter\Tests;
|
||||
|
||||
use Drupal\config_filter\Config\GhostStorage;
|
||||
use Drupal\Core\Config\StorageInterface;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* Tests GhostStorage operations.
|
||||
*
|
||||
* @group config_filter
|
||||
*/
|
||||
class GhostStorageTest extends ReadonlyStorageTest {
|
||||
|
||||
/**
|
||||
* Override the storage decorating.
|
||||
*
|
||||
* @param \Drupal\Core\Config\StorageInterface $source
|
||||
* The storage to decorate.
|
||||
*
|
||||
* @return \Drupal\config_filter\Config\GhostStorage
|
||||
* The storage to test.
|
||||
*/
|
||||
protected function getStorage(StorageInterface $source) {
|
||||
return new GhostStorage($source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the dataprovider for write methods.
|
||||
*
|
||||
* @dataProvider writeMethodsProvider
|
||||
*/
|
||||
public function testWriteOperations($method, $arguments) {
|
||||
$source = $this->prophesize(StorageInterface::class);
|
||||
$source->$method(Argument::any())->shouldNotBeCalled();
|
||||
|
||||
$storage = $this->getStorage($source->reveal());
|
||||
|
||||
$actual = call_user_func_array([$storage, $method], $arguments);
|
||||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -3,10 +3,10 @@ type: module
|
||||
# core: 8.x
|
||||
package: Testing
|
||||
dependencies:
|
||||
- drupal:config_filter
|
||||
- config_filter:config_filter
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-27
|
||||
version: '8.x-1.1'
|
||||
# Information added by Drupal.org packaging script on 2018-04-05
|
||||
version: '8.x-1.2'
|
||||
core: '8.x'
|
||||
project: 'config_filter'
|
||||
datestamp: 1511779987
|
||||
datestamp: 1522943894
|
||||
|
||||
+4
-4
@@ -3,10 +3,10 @@ type: module
|
||||
# core: 8.x
|
||||
package: Testing
|
||||
dependencies:
|
||||
- drupal:config_filter
|
||||
- config_filter:config_filter
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-27
|
||||
version: '8.x-1.1'
|
||||
# Information added by Drupal.org packaging script on 2018-04-05
|
||||
version: '8.x-1.2'
|
||||
core: '8.x'
|
||||
project: 'config_filter'
|
||||
datestamp: 1511779987
|
||||
datestamp: 1522943894
|
||||
|
||||
Reference in New Issue
Block a user