class ConfigFilterEventSubscriber in Config Filter 8.2
Class ConfigFilterEventSubscriber.
Hierarchy
- class \Drupal\config_filter\ConfigFilterEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses StorageCopyTrait
Expanded class hierarchy of ConfigFilterEventSubscriber
1 string reference to 'ConfigFilterEventSubscriber'
1 service uses ConfigFilterEventSubscriber
File
- src/
ConfigFilterEventSubscriber.php, line 14
Namespace
Drupal\config_filterView source
class ConfigFilterEventSubscriber implements EventSubscriberInterface {
use StorageCopyTrait;
/**
* The filter storage factory.
*
* @var \Drupal\config_filter\ConfigFilterStorageFactory
*/
protected $filterStorageFactory;
/**
* The sync storage.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected $sync;
/**
* ConfigFilterEventSubscriber constructor.
*
* @param \Drupal\config_filter\ConfigFilterStorageFactory $filterStorageFactory
* The filter storage factory.
* @param \Drupal\Core\Config\StorageInterface $sync
* The sync storage.
*/
public function __construct(ConfigFilterStorageFactory $filterStorageFactory, StorageInterface $sync) {
$this->filterStorageFactory = $filterStorageFactory;
$this->sync = $sync;
}
/**
* The storage is transformed for importing.
*
* @param \Drupal\Core\Config\StorageTransformEvent $event
* The event for altering configuration of the storage.
*/
public function onImportTransform(StorageTransformEvent $event) {
$storage = $event
->getStorage();
// The temporary storage representing the active storage.
$temp = new MemoryStorage();
// Get the filtered storage based on the event storage.
$filtered = $this->filterStorageFactory
->getFilteredStorage($storage, [
'config.storage.sync',
]);
// Simulate the importing of configuration.
self::replaceStorageContents($filtered, $temp);
// Set the event storage to the one of the simulated import.
self::replaceStorageContents($temp, $storage);
}
/**
* The storage is transformed for exporting.
*
* @param \Drupal\Core\Config\StorageTransformEvent $event
* The event for altering configuration of the storage.
*/
public function onExportTransform(StorageTransformEvent $event) {
$storage = $event
->getStorage();
// The temporary storage representing the sync storage.
$temp = new MemoryStorage();
// Copy the contents of the sync storage to the temporary one.
self::replaceStorageContents($this->sync, $temp);
// Get the simulated filtered sync storage.
$filtered = $this->filterStorageFactory
->getFilteredStorage($temp, [
'config.storage.sync',
]);
// Simulate the exporting of the configuration.
self::replaceStorageContents($storage, $filtered);
// Set the event storage to the inner storage of the simulated sync storage.
self::replaceStorageContents($temp, $storage);
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
// @todo: use class constants when they get added in #2991683
$events['config.transform.import'][] = [
'onImportTransform',
];
$events['config.transform.export'][] = [
'onExportTransform',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFilterEventSubscriber:: |
protected | property | The filter storage factory. | |
ConfigFilterEventSubscriber:: |
protected | property | The sync storage. | |
ConfigFilterEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ConfigFilterEventSubscriber:: |
public | function | The storage is transformed for exporting. | |
ConfigFilterEventSubscriber:: |
public | function | The storage is transformed for importing. | |
ConfigFilterEventSubscriber:: |
public | function | ConfigFilterEventSubscriber constructor. | |
StorageCopyTrait:: |
protected static | function | Copy the configuration from one storage to another and remove stale items. |