Loading core/modules/config_environment/config_environment.module +0 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ // See the experimental modules policy https://www.drupal.org/core/experimental // @todo: remove class aliases in #2991683 @class_alias('Drupal\config_environment\Core\Config\StorageTransformEvent', 'Drupal\Core\Config\StorageTransformEvent'); @class_alias('Drupal\config_environment\Core\Config\StorageRebuildNeededEvent', 'Drupal\Core\Config\StorageRebuildNeededEvent'); @class_alias('Drupal\config_environment\Core\Config\ManagedStorage', 'Drupal\Core\Config\ManagedStorage'); @class_alias('Drupal\config_environment\Core\Config\StorageManagerInterface', 'Drupal\Core\Config\StorageManagerInterface'); @class_alias('Drupal\config_environment\Core\Config\ExportStorageManager', 'Drupal\Core\Config\ExportStorageManager'); Loading core/modules/config_environment/config_environment.services.yml +2 −4 Original line number Diff line number Diff line Loading @@ -8,12 +8,10 @@ services: arguments: ['@config.storage.export.manager'] config.storage.export.manager: class: Drupal\config_environment\Core\Config\ExportStorageManager arguments: ['@config.storage', '@state', '@database', '@event_dispatcher'] tags: - { name: event_subscriber } arguments: ['@config.storage', '@database', '@event_dispatcher'] # config_environment services. config_environment.excluded_modules.event_subscriber: class: Drupal\config_environment\EventSubscriber\ExcludedModulesEventSubscriber arguments: ['@config.storage', '@settings', '@config.manager', '@state'] arguments: ['@config.storage', '@settings', '@config.manager'] tags: - { name: event_subscriber } core/modules/config_environment/src/Core/Config/ConfigEvents.php +0 −28 Original line number Diff line number Diff line Loading @@ -71,38 +71,10 @@ final class ConfigEvents { * * @see \Drupal\Core\Config\StorageTransformEvent * @see \Drupal\Core\Config\ConfigEvents::STORAGE_TRANSFORM_IMPORT * @see \Drupal\Core\Config\ConfigEvents::STORAGE_EXPORT_REBUILD * @see \Drupal\config_environment\Core\Config\ExportStorageManager::getStorage * * @var string */ const STORAGE_TRANSFORM_EXPORT = 'config.transform.export'; /** * Name of the event fired when the export storage may need to be rebuilt. * * This event allows subscribers to indicate that the export storage should be * rebuilt. The event listener method receives a * \Drupal\Core\Config\StorageRebuildNeededEvent instance. * When this event is set to be needing a rebuild by a subscriber then the * \Drupal\Core\Config\ConfigEvents::STORAGE_TRANSFORM_EXPORT event will be * dispatched. * * @code * if ($exportStorageIsOutOfDateConditionIsMet) { * $event->setRebuildNeeded(); * } * // else, do nothing. * @endcode * * @Event * * @see \Drupal\Core\Config\StorageRebuildNeededEvent * @see \Drupal\Core\Config\ConfigEvents::STORAGE_TRANSFORM_EXPORT * @see \Drupal\config_environment\Core\Config\ExportStorageManager::getStorage * * @var string */ const STORAGE_EXPORT_REBUILD = 'config.export.rebuild'; } core/modules/config_environment/src/Core/Config/ExportStorageManager.php +5 −50 Original line number Diff line number Diff line Loading @@ -6,30 +6,22 @@ // @codingStandardsIgnoreEnd namespace Drupal\config_environment\Core\Config; use Drupal\Core\Config\ConfigEvents; use Drupal\Core\Config\DatabaseStorage; use Drupal\Core\Config\ReadOnlyStorage; use Drupal\Core\Config\StorageCopyTrait; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Database\Connection; use Drupal\Core\State\StateInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * The export storage manager dispatches an event for the export storage. * * @internal */ class ExportStorageManager implements StorageManagerInterface, EventSubscriberInterface { class ExportStorageManager implements StorageManagerInterface { use StorageCopyTrait; /** * The state key indicating that the export storage needs to be rebuilt. */ const NEEDS_REBUILD_KEY = 'config_export_needs_rebuild'; /** * The active configuration storage. * Loading @@ -37,13 +29,6 @@ class ExportStorageManager implements StorageManagerInterface, EventSubscriberIn */ protected $active; /** * The drupal state. * * @var \Drupal\Core\State\StateInterface */ protected $state; /** * The database storage. * Loading @@ -63,16 +48,13 @@ class ExportStorageManager implements StorageManagerInterface, EventSubscriberIn * * @param \Drupal\Core\Config\StorageInterface $active * The active config storage to prime the export storage. * @param \Drupal\Core\State\StateInterface $state * The drupal state. * @param \Drupal\Core\Database\Connection $connection * The database connection. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * The event dispatcher. */ public function __construct(StorageInterface $active, StateInterface $state, Connection $connection, EventDispatcherInterface $event_dispatcher) { public function __construct(StorageInterface $active, Connection $connection, EventDispatcherInterface $event_dispatcher) { $this->active = $active; $this->state = $state; $this->eventDispatcher = $event_dispatcher; // The point of this service is to provide the storage and dispatch the // event when needed, so the storage itself can not be a service. Loading @@ -83,38 +65,11 @@ public function __construct(StorageInterface $active, StateInterface $state, Con * {@inheritdoc} */ public function getStorage() { $rebuild = $this->state->get(self::NEEDS_REBUILD_KEY, TRUE); if (!$rebuild) { // @todo: Use ConfigEvents::STORAGE_EXPORT_REBUILD in #2991683 $rebuild = $this->eventDispatcher->dispatch('config.export.rebuild', new StorageRebuildNeededEvent())->isRebuildNeeded(); } if ($rebuild) { self::replaceStorageContents($this->active, $this->storage); // @todo: Use ConfigEvents::STORAGE_TRANSFORM_EXPORT in #2991683 $this->eventDispatcher->dispatch('config.transform.export', new StorageTransformEvent($this->storage)); $this->state->set(self::NEEDS_REBUILD_KEY, FALSE); } return new ReadOnlyStorage($this->storage); } /** * {@inheritdoc} */ public static function getSubscribedEvents() { $events[ConfigEvents::SAVE][] = ['onConfigChange', 0]; $events[ConfigEvents::DELETE][] = ['onConfigChange', 0]; $events[ConfigEvents::RENAME][] = ['onConfigChange', 0]; return $events; } /** * Set the flag in state that the export storage is out of date. */ public function onConfigChange() { if (!$this->state->get(self::NEEDS_REBUILD_KEY, FALSE)) { $this->state->set(self::NEEDS_REBUILD_KEY, TRUE); } } } core/modules/config_environment/src/Core/Config/StorageRebuildNeededEvent.phpdeleted 100644 → 0 +0 −37 Original line number Diff line number Diff line <?php namespace Drupal\config_environment\Core\Config; use Symfony\Component\EventDispatcher\Event; /** * The dispatched by a storage manager to check if a rebuild is needed. */ class StorageRebuildNeededEvent extends Event { /** * The flag which keeps track of whether the storage needs to be rebuilt. * * @var bool */ private $rebuildNeeded = FALSE; /** * Flags to the config storage manager that a rebuild is needed. */ public function setRebuildNeeded() { $this->rebuildNeeded = TRUE; $this->stopPropagation(); } /** * Returns whether the storage needs to be rebuilt or not. * * @return bool * Whether the rebuild is needed or not. */ public function isRebuildNeeded() { return $this->rebuildNeeded; } } Loading
core/modules/config_environment/config_environment.module +0 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ // See the experimental modules policy https://www.drupal.org/core/experimental // @todo: remove class aliases in #2991683 @class_alias('Drupal\config_environment\Core\Config\StorageTransformEvent', 'Drupal\Core\Config\StorageTransformEvent'); @class_alias('Drupal\config_environment\Core\Config\StorageRebuildNeededEvent', 'Drupal\Core\Config\StorageRebuildNeededEvent'); @class_alias('Drupal\config_environment\Core\Config\ManagedStorage', 'Drupal\Core\Config\ManagedStorage'); @class_alias('Drupal\config_environment\Core\Config\StorageManagerInterface', 'Drupal\Core\Config\StorageManagerInterface'); @class_alias('Drupal\config_environment\Core\Config\ExportStorageManager', 'Drupal\Core\Config\ExportStorageManager'); Loading
core/modules/config_environment/config_environment.services.yml +2 −4 Original line number Diff line number Diff line Loading @@ -8,12 +8,10 @@ services: arguments: ['@config.storage.export.manager'] config.storage.export.manager: class: Drupal\config_environment\Core\Config\ExportStorageManager arguments: ['@config.storage', '@state', '@database', '@event_dispatcher'] tags: - { name: event_subscriber } arguments: ['@config.storage', '@database', '@event_dispatcher'] # config_environment services. config_environment.excluded_modules.event_subscriber: class: Drupal\config_environment\EventSubscriber\ExcludedModulesEventSubscriber arguments: ['@config.storage', '@settings', '@config.manager', '@state'] arguments: ['@config.storage', '@settings', '@config.manager'] tags: - { name: event_subscriber }
core/modules/config_environment/src/Core/Config/ConfigEvents.php +0 −28 Original line number Diff line number Diff line Loading @@ -71,38 +71,10 @@ final class ConfigEvents { * * @see \Drupal\Core\Config\StorageTransformEvent * @see \Drupal\Core\Config\ConfigEvents::STORAGE_TRANSFORM_IMPORT * @see \Drupal\Core\Config\ConfigEvents::STORAGE_EXPORT_REBUILD * @see \Drupal\config_environment\Core\Config\ExportStorageManager::getStorage * * @var string */ const STORAGE_TRANSFORM_EXPORT = 'config.transform.export'; /** * Name of the event fired when the export storage may need to be rebuilt. * * This event allows subscribers to indicate that the export storage should be * rebuilt. The event listener method receives a * \Drupal\Core\Config\StorageRebuildNeededEvent instance. * When this event is set to be needing a rebuild by a subscriber then the * \Drupal\Core\Config\ConfigEvents::STORAGE_TRANSFORM_EXPORT event will be * dispatched. * * @code * if ($exportStorageIsOutOfDateConditionIsMet) { * $event->setRebuildNeeded(); * } * // else, do nothing. * @endcode * * @Event * * @see \Drupal\Core\Config\StorageRebuildNeededEvent * @see \Drupal\Core\Config\ConfigEvents::STORAGE_TRANSFORM_EXPORT * @see \Drupal\config_environment\Core\Config\ExportStorageManager::getStorage * * @var string */ const STORAGE_EXPORT_REBUILD = 'config.export.rebuild'; }
core/modules/config_environment/src/Core/Config/ExportStorageManager.php +5 −50 Original line number Diff line number Diff line Loading @@ -6,30 +6,22 @@ // @codingStandardsIgnoreEnd namespace Drupal\config_environment\Core\Config; use Drupal\Core\Config\ConfigEvents; use Drupal\Core\Config\DatabaseStorage; use Drupal\Core\Config\ReadOnlyStorage; use Drupal\Core\Config\StorageCopyTrait; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Database\Connection; use Drupal\Core\State\StateInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * The export storage manager dispatches an event for the export storage. * * @internal */ class ExportStorageManager implements StorageManagerInterface, EventSubscriberInterface { class ExportStorageManager implements StorageManagerInterface { use StorageCopyTrait; /** * The state key indicating that the export storage needs to be rebuilt. */ const NEEDS_REBUILD_KEY = 'config_export_needs_rebuild'; /** * The active configuration storage. * Loading @@ -37,13 +29,6 @@ class ExportStorageManager implements StorageManagerInterface, EventSubscriberIn */ protected $active; /** * The drupal state. * * @var \Drupal\Core\State\StateInterface */ protected $state; /** * The database storage. * Loading @@ -63,16 +48,13 @@ class ExportStorageManager implements StorageManagerInterface, EventSubscriberIn * * @param \Drupal\Core\Config\StorageInterface $active * The active config storage to prime the export storage. * @param \Drupal\Core\State\StateInterface $state * The drupal state. * @param \Drupal\Core\Database\Connection $connection * The database connection. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * The event dispatcher. */ public function __construct(StorageInterface $active, StateInterface $state, Connection $connection, EventDispatcherInterface $event_dispatcher) { public function __construct(StorageInterface $active, Connection $connection, EventDispatcherInterface $event_dispatcher) { $this->active = $active; $this->state = $state; $this->eventDispatcher = $event_dispatcher; // The point of this service is to provide the storage and dispatch the // event when needed, so the storage itself can not be a service. Loading @@ -83,38 +65,11 @@ public function __construct(StorageInterface $active, StateInterface $state, Con * {@inheritdoc} */ public function getStorage() { $rebuild = $this->state->get(self::NEEDS_REBUILD_KEY, TRUE); if (!$rebuild) { // @todo: Use ConfigEvents::STORAGE_EXPORT_REBUILD in #2991683 $rebuild = $this->eventDispatcher->dispatch('config.export.rebuild', new StorageRebuildNeededEvent())->isRebuildNeeded(); } if ($rebuild) { self::replaceStorageContents($this->active, $this->storage); // @todo: Use ConfigEvents::STORAGE_TRANSFORM_EXPORT in #2991683 $this->eventDispatcher->dispatch('config.transform.export', new StorageTransformEvent($this->storage)); $this->state->set(self::NEEDS_REBUILD_KEY, FALSE); } return new ReadOnlyStorage($this->storage); } /** * {@inheritdoc} */ public static function getSubscribedEvents() { $events[ConfigEvents::SAVE][] = ['onConfigChange', 0]; $events[ConfigEvents::DELETE][] = ['onConfigChange', 0]; $events[ConfigEvents::RENAME][] = ['onConfigChange', 0]; return $events; } /** * Set the flag in state that the export storage is out of date. */ public function onConfigChange() { if (!$this->state->get(self::NEEDS_REBUILD_KEY, FALSE)) { $this->state->set(self::NEEDS_REBUILD_KEY, TRUE); } } }
core/modules/config_environment/src/Core/Config/StorageRebuildNeededEvent.phpdeleted 100644 → 0 +0 −37 Original line number Diff line number Diff line <?php namespace Drupal\config_environment\Core\Config; use Symfony\Component\EventDispatcher\Event; /** * The dispatched by a storage manager to check if a rebuild is needed. */ class StorageRebuildNeededEvent extends Event { /** * The flag which keeps track of whether the storage needs to be rebuilt. * * @var bool */ private $rebuildNeeded = FALSE; /** * Flags to the config storage manager that a rebuild is needed. */ public function setRebuildNeeded() { $this->rebuildNeeded = TRUE; $this->stopPropagation(); } /** * Returns whether the storage needs to be rebuilt or not. * * @return bool * Whether the rebuild is needed or not. */ public function isRebuildNeeded() { return $this->rebuildNeeded; } }