class ConfigEventSubscriber in Tome 8
Keeps the config export directory synced with config CRUD operations.
@internal
Hierarchy
- class \Drupal\tome_sync\EventSubscriber\ConfigEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ConfigEventSubscriber
1 string reference to 'ConfigEventSubscriber'
- tome_sync.services.yml in modules/
tome_sync/ tome_sync.services.yml - modules/tome_sync/tome_sync.services.yml
1 service uses ConfigEventSubscriber
File
- modules/
tome_sync/ src/ EventSubscriber/ ConfigEventSubscriber.php, line 16
Namespace
Drupal\tome_sync\EventSubscriberView source
class ConfigEventSubscriber implements EventSubscriberInterface {
/**
* The config storage.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected $configStorage;
/**
* Constructs the ConfigEventSubscriber object.
*
* @param \Drupal\Core\Config\StorageInterface $config_storage
* The config storage.
*/
public function __construct(StorageInterface $config_storage) {
$this->configStorage = $config_storage;
}
/**
* Reacts to a save event.
*
* @param \Drupal\Core\Config\ConfigCrudEvent $event
* The configuration event.
*/
public function configSave(ConfigCrudEvent $event) {
if (!\Drupal::isConfigSyncing() && !isset($GLOBALS['_tome_sync_installing'])) {
$config = $event
->getConfig();
$this->configStorage
->write($config
->getName(), $config
->getRawData());
}
}
/**
* Reacts to delete event.
*
* @param \Drupal\Core\Config\ConfigCrudEvent $event
* The configuration event.
*/
public function configDelete(ConfigCrudEvent $event) {
if (!\Drupal::isConfigSyncing() && !isset($GLOBALS['_tome_sync_installing'])) {
$this->configStorage
->delete($event
->getConfig()
->getName());
}
}
/**
* Reacts to rename event.
*
* @param \Drupal\Core\Config\ConfigRenameEvent $event
* The configuration event.
*/
public function configRename(ConfigRenameEvent $event) {
if (!\Drupal::isConfigSyncing() && !isset($GLOBALS['_tome_sync_installing'])) {
$this->configStorage
->rename($event
->getOldName(), $event
->getConfig()
->getName());
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[ConfigEvents::SAVE][] = [
'configSave',
];
$events[ConfigEvents::DELETE][] = [
'configDelete',
];
$events[ConfigEvents::RENAME][] = [
'configRename',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigEventSubscriber:: |
protected | property | The config storage. | |
ConfigEventSubscriber:: |
public | function | Reacts to delete event. | |
ConfigEventSubscriber:: |
public | function | Reacts to rename event. | |
ConfigEventSubscriber:: |
public | function | Reacts to a save event. | |
ConfigEventSubscriber:: |
public static | function | ||
ConfigEventSubscriber:: |
public | function | Constructs the ConfigEventSubscriber object. |