class LanguageConfigEventSubscriber in Tome 8
Keeps the config export directory synced with language config operations.
@internal
Hierarchy
- class \Drupal\tome_sync\EventSubscriber\LanguageConfigEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of LanguageConfigEventSubscriber
1 file declares its use of LanguageConfigEventSubscriber
- TomeSyncServiceProvider.php in modules/
tome_sync/ src/ TomeSyncServiceProvider.php
File
- modules/
tome_sync/ src/ EventSubscriber/ LanguageConfigEventSubscriber.php, line 15
Namespace
Drupal\tome_sync\EventSubscriberView source
class LanguageConfigEventSubscriber 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\language\Config\LanguageConfigOverrideCrudEvent $event
* The configuration event.
*/
public function configSave(LanguageConfigOverrideCrudEvent $event) {
if (!\Drupal::isConfigSyncing()) {
$override = $event
->getLanguageConfigOverride();
$collection = $this->configStorage
->createCollection($override
->getStorage()
->getCollectionName());
$name = $override
->getName();
$collection
->write($name, $override
->get());
}
}
/**
* Reacts to delete event.
*
* @param \Drupal\language\Config\LanguageConfigOverrideCrudEvent $event
* The configuration event.
*/
public function configDelete(LanguageConfigOverrideCrudEvent $event) {
if (!\Drupal::isConfigSyncing()) {
$override = $event
->getLanguageConfigOverride();
$collection = $this->configStorage
->createCollection($override
->getStorage()
->getCollectionName());
$name = $override
->getName();
$collection
->delete($name);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[LanguageConfigOverrideEvents::SAVE_OVERRIDE][] = [
'configSave',
];
$events[LanguageConfigOverrideEvents::DELETE_OVERRIDE][] = [
'configDelete',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LanguageConfigEventSubscriber:: |
protected | property | The config storage. | |
LanguageConfigEventSubscriber:: |
public | function | Reacts to delete event. | |
LanguageConfigEventSubscriber:: |
public | function | Reacts to a save event. | |
LanguageConfigEventSubscriber:: |
public static | function | ||
LanguageConfigEventSubscriber:: |
public | function | Constructs the ConfigEventSubscriber object. |