Loading config_split.services.yml +5 −0 Original line number Diff line number Diff line Loading @@ -43,5 +43,10 @@ services: arguments: - "@state" - "@cache_tags.invalidator" config_split.status_config_factory_override: class: Drupal\config_split\Config\StatusConfigFactoryOverride arguments: - "@state" tags: - { name: config.factory.override, priority: 5 } src/Config/StatusConfigFactoryOverride.php 0 → 100644 +71 −0 Original line number Diff line number Diff line <?php namespace Drupal\config_split\Config; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Config\ConfigFactoryOverrideInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\State\StateInterface; /** * A config factory override for config split based on the drupal state. * * @see \Drupal\config_split\Config\StatusOverride */ class StatusConfigFactoryOverride implements ConfigFactoryOverrideInterface { /** * The drupal state. * * @var \Drupal\Core\State\StateInterface */ protected $state; /** * The service constructor. * * @param \Drupal\Core\State\StateInterface $state * The drupal state. */ public function __construct(StateInterface $state) { $this->state = $state; } /** * {@inheritdoc} */ public function loadOverrides($names) { $overrides = []; foreach ($this->state->get('config_split_override_state', []) as $name => $status) { $name = 'config_split.config_split.' . $name; if (in_array($name, $names)) { $overrides = $overrides + [$name => ['status' => (bool) $status]]; } } return $overrides; } /** * {@inheritdoc} */ public function getCacheSuffix() { return 'config_split_state'; } /** * {@inheritdoc} */ public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { return NULL; } /** * {@inheritdoc} */ public function getCacheableMetadata($name) { return new CacheableMetadata(); } } src/Config/StatusOverride.php +5 −43 Original line number Diff line number Diff line Loading @@ -2,16 +2,15 @@ namespace Drupal\config_split\Config; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\CacheTagsInvalidatorInterface; use Drupal\Core\Config\ConfigFactoryOverrideInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\State\StateInterface; /** * A config override for config split based on the drupal state. * A service for config override for config split based on the drupal state. * * @see \Drupal\config_split\Config\StatusConfigFactoryOverride */ class StatusOverride implements ConfigFactoryOverrideInterface { class StatusOverride { /** * The drupal state. Loading Loading @@ -58,7 +57,7 @@ public function setSplitOverride(string $name, bool $active = NULL) { $overrides[$name] = $active; } $this->state->set('config_split_override_state', $overrides); $this->cacheInvalidator->invalidateTags($this->getCacheableMetadata('config_split.config_split.' . $name)->getCacheTags()); $this->cacheInvalidator->invalidateTags(['config:config_split.config_split.' . $name]); } /** Loading Loading @@ -97,43 +96,6 @@ public function getSettingsOverride(string $name) { return NULL; } /** * {@inheritdoc} */ public function loadOverrides($names) { $overrides = []; foreach ($this->state->get('config_split_override_state', []) as $name => $status) { $name = 'config_split.config_split.' . $name; if (in_array($name, $names)) { $overrides = $overrides + [$name => ['status' => (bool) $status]]; } } return $overrides; } /** * {@inheritdoc} */ public function getCacheSuffix() { return 'config_split_state'; } /** * {@inheritdoc} */ public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { return NULL; } /** * {@inheritdoc} */ public function getCacheableMetadata($name) { return new CacheableMetadata(); } /** * Make sure the split name is just the machine name. * Loading Loading
config_split.services.yml +5 −0 Original line number Diff line number Diff line Loading @@ -43,5 +43,10 @@ services: arguments: - "@state" - "@cache_tags.invalidator" config_split.status_config_factory_override: class: Drupal\config_split\Config\StatusConfigFactoryOverride arguments: - "@state" tags: - { name: config.factory.override, priority: 5 }
src/Config/StatusConfigFactoryOverride.php 0 → 100644 +71 −0 Original line number Diff line number Diff line <?php namespace Drupal\config_split\Config; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Config\ConfigFactoryOverrideInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\State\StateInterface; /** * A config factory override for config split based on the drupal state. * * @see \Drupal\config_split\Config\StatusOverride */ class StatusConfigFactoryOverride implements ConfigFactoryOverrideInterface { /** * The drupal state. * * @var \Drupal\Core\State\StateInterface */ protected $state; /** * The service constructor. * * @param \Drupal\Core\State\StateInterface $state * The drupal state. */ public function __construct(StateInterface $state) { $this->state = $state; } /** * {@inheritdoc} */ public function loadOverrides($names) { $overrides = []; foreach ($this->state->get('config_split_override_state', []) as $name => $status) { $name = 'config_split.config_split.' . $name; if (in_array($name, $names)) { $overrides = $overrides + [$name => ['status' => (bool) $status]]; } } return $overrides; } /** * {@inheritdoc} */ public function getCacheSuffix() { return 'config_split_state'; } /** * {@inheritdoc} */ public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { return NULL; } /** * {@inheritdoc} */ public function getCacheableMetadata($name) { return new CacheableMetadata(); } }
src/Config/StatusOverride.php +5 −43 Original line number Diff line number Diff line Loading @@ -2,16 +2,15 @@ namespace Drupal\config_split\Config; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\CacheTagsInvalidatorInterface; use Drupal\Core\Config\ConfigFactoryOverrideInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\State\StateInterface; /** * A config override for config split based on the drupal state. * A service for config override for config split based on the drupal state. * * @see \Drupal\config_split\Config\StatusConfigFactoryOverride */ class StatusOverride implements ConfigFactoryOverrideInterface { class StatusOverride { /** * The drupal state. Loading Loading @@ -58,7 +57,7 @@ public function setSplitOverride(string $name, bool $active = NULL) { $overrides[$name] = $active; } $this->state->set('config_split_override_state', $overrides); $this->cacheInvalidator->invalidateTags($this->getCacheableMetadata('config_split.config_split.' . $name)->getCacheTags()); $this->cacheInvalidator->invalidateTags(['config:config_split.config_split.' . $name]); } /** Loading Loading @@ -97,43 +96,6 @@ public function getSettingsOverride(string $name) { return NULL; } /** * {@inheritdoc} */ public function loadOverrides($names) { $overrides = []; foreach ($this->state->get('config_split_override_state', []) as $name => $status) { $name = 'config_split.config_split.' . $name; if (in_array($name, $names)) { $overrides = $overrides + [$name => ['status' => (bool) $status]]; } } return $overrides; } /** * {@inheritdoc} */ public function getCacheSuffix() { return 'config_split_state'; } /** * {@inheritdoc} */ public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { return NULL; } /** * {@inheritdoc} */ public function getCacheableMetadata($name) { return new CacheableMetadata(); } /** * Make sure the split name is just the machine name. * Loading