class TestSplitFilter in Config Filter 8
Same name and namespace in other branches
- 8.2 tests/modules/config_filter_split_test/src/Plugin/ConfigFilter/TestSplitFilter.php \Drupal\config_filter_split_test\Plugin\ConfigFilter\TestSplitFilter
Provides a TestSplitFilter.
This is a very basic split filter to test that config_filter applies the filters correctly. For more advanced and configurable split filters use the Configuration Split (config_split) module.
Plugin annotation
@ConfigFilter(
id = "config_filter_split_test",
label = @Translation("Filter Split test"),
storages = {"test_storage"},
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\config_filter\Plugin\ConfigFilterBase implements ConfigFilterInterface uses TransparentStorageFilterTrait
- class \Drupal\config_filter_split_test\Plugin\ConfigFilter\TestSplitFilter implements ContainerFactoryPluginInterface
- class \Drupal\config_filter\Plugin\ConfigFilterBase implements ConfigFilterInterface uses TransparentStorageFilterTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of TestSplitFilter
File
- tests/
modules/ config_filter_split_test/ src/ Plugin/ ConfigFilter/ TestSplitFilter.php, line 24
Namespace
Drupal\config_filter_split_test\Plugin\ConfigFilterView source
class TestSplitFilter extends ConfigFilterBase implements ContainerFactoryPluginInterface {
/**
* The File storage to read the migrations from.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected $storage;
/**
* The name prefix to split.
*
* @var string
*/
protected $name;
/**
* Constructs a new TestSplitFilter.
*
* @param \Drupal\Core\Config\StorageInterface $storage
* The migrate storage.
* @param string $name
* The config name prefix to split.
*/
public function __construct(StorageInterface $storage, $name) {
parent::__construct([], 'config_filter_split_test', []);
$this->storage = $storage;
$this->name = $name;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(new DatabaseStorage($container
->get('database'), 'config_filter_split_test'), 'core.');
}
/**
* Decide to split the config off or not.
*
* @param string $name
* The name of the configuration to check.
*
* @return bool
* Whether the configuration is supposed to be split.
*/
protected function isSplitConfig($name) {
return strpos($name, $this->name) === 0;
}
/**
* {@inheritdoc}
*/
public function filterRead($name, $data) {
if ($this
->isSplitConfig($name)) {
if ($this->storage
->exists($name)) {
$data = $this->storage
->read($name);
}
}
return $data;
}
/**
* {@inheritdoc}
*/
public function filterExists($name, $exists) {
if ($this
->isSplitConfig($name) && !$exists) {
$exists = $this->storage
->exists($name);
}
return $exists;
}
/**
* {@inheritdoc}
*/
public function filterReadMultiple(array $names, array $data) {
return array_merge($data, $this->storage
->readMultiple($names));
}
/**
* {@inheritdoc}
*/
public function filterListAll($prefix, array $data) {
return array_unique(array_merge($data, $this->storage
->listAll($prefix)));
}
/**
* {@inheritdoc}
*/
public function filterWrite($name, array $data) {
if ($this
->isSplitConfig($name)) {
$this->storage
->write($name, $data);
return NULL;
}
return $data;
}
/**
* {@inheritdoc}
*/
public function filterWriteEmptyIsDelete($name) {
return $this
->isSplitConfig($name) ? TRUE : NULL;
}
/**
* {@inheritdoc}
*/
public function filterDelete($name, $delete) {
if ($delete && $this->storage
->exists($name)) {
// Call delete on the secondary storage anyway.
$this->storage
->delete($name);
}
return $delete;
}
/**
* {@inheritdoc}
*/
public function filterDeleteAll($prefix, $delete) {
if ($delete && $this->storage) {
try {
$this->storage
->deleteAll($prefix);
} catch (\UnexpectedValueException $exception) {
// The file storage tries to remove directories of collections. But this
// fails if the directory doesn't exist. So everything is actually fine.
}
}
return $delete;
}
/**
* {@inheritdoc}
*/
public function filterCreateCollection($collection) {
return new static($this->storage
->createCollection($collection), $this->name);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
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. | |
TestSplitFilter:: |
protected | property | The name prefix to split. | |
TestSplitFilter:: |
protected | property | The File storage to read the migrations from. | |
TestSplitFilter:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
TestSplitFilter:: |
public | function |
Overrides TransparentStorageFilterTrait:: |
|
TestSplitFilter:: |
public | function |
Overrides TransparentStorageFilterTrait:: |
|
TestSplitFilter:: |
public | function |
Overrides TransparentStorageFilterTrait:: |
|
TestSplitFilter:: |
public | function |
Overrides TransparentStorageFilterTrait:: |
|
TestSplitFilter:: |
public | function |
Overrides TransparentStorageFilterTrait:: |
|
TestSplitFilter:: |
public | function |
Overrides TransparentStorageFilterTrait:: |
|
TestSplitFilter:: |
public | function |
Overrides TransparentStorageFilterTrait:: |
|
TestSplitFilter:: |
public | function |
Overrides TransparentStorageFilterTrait:: |
|
TestSplitFilter:: |
public | function |
Overrides TransparentStorageFilterTrait:: |
|
TestSplitFilter:: |
protected | function | Decide to split the config off or not. | |
TestSplitFilter:: |
public | function |
Constructs a new TestSplitFilter. Overrides PluginBase:: |
|
TransparentStorageFilterTrait:: |
protected | property | The wrapped storage which calls the filter. | |
TransparentStorageFilterTrait:: |
protected | property | The read-only source storage on which the filter operations are performed. | |
TransparentStorageFilterTrait:: |
public | function | ||
TransparentStorageFilterTrait:: |
public | function | ||
TransparentStorageFilterTrait:: |
public | function | ||
TransparentStorageFilterTrait:: |
protected | function | Get the decorator storage which applies the filters. | |
TransparentStorageFilterTrait:: |
protected | function | Get the read-only source Storage. | |
TransparentStorageFilterTrait:: |
public | function | ||
TransparentStorageFilterTrait:: |
public | function |