diff --git a/core/core.services.yml b/core/core.services.yml index bb65f34..411e3f6 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -85,11 +85,21 @@ services: config.installer: class: Drupal\Core\Config\ConfigInstaller arguments: ['@config.factory', '@config.storage', '@config.typed', '@config.manager', '@event_dispatcher'] + # Runtime configuration storage; dependency for other services. + # MAY be cached. config.storage: alias: config.storage.active + # Actual storage used for runtime configuration. + # MUST NOT be cached. config.storage.active: + class: Drupal\Core\Config\Storage\ChainWriteStorage + tags: + - { name: service_collector, call: addStorage } + config.storage.database: class: Drupal\Core\Config\DatabaseStorage arguments: ['@database', 'config'] + tags: + - { name: 'config.storage.active', priority: 100 } config.storage.file: class: Drupal\Core\Config\FileStorage factory_class: Drupal\Core\Config\FileStorageFactory diff --git a/core/lib/Drupal/Core/Config/Storage/ChainWriteStorage.php b/core/lib/Drupal/Core/Config/Storage/ChainWriteStorage.php new file mode 100644 index 0000000..967f67f --- /dev/null +++ b/core/lib/Drupal/Core/Config/Storage/ChainWriteStorage.php @@ -0,0 +1,147 @@ +storage)) { + $this->storage = $storage; + } + else { + $this->secondary[] = $storage; + } + return $this; + } + + /** + * {@inheritdoc} + */ + public function exists($name) { + return $this->storage->exists($name); + } + + /** + * {@inheritdoc} + */ + public function listAll($prefix = '') { + return $this->storage->listAll($prefix); + } + + /** + * {@inheritdoc} + */ + public function read($name) { + return $this->storage->read($name); + } + + /** + * {@inheritdoc} + */ + public function readMultiple(array $names) { + return $this->storage->readMultiple($names); + } + + /** + * {@inheritdoc} + */ + public function write($name, array $data) { + if ($this->storage->write($name, $data)) { + foreach ($this->secondary as $storage) { + $storage->write($name, $data); + } + return TRUE; + } + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function delete($name) { + if ($this->storage->delete($name)) { + foreach ($this->secondary as $storage) { + $storage->delete($name); + } + return TRUE; + } + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function deleteAll($prefix = '') { + if ($this->storage->deleteAll($prefix)) { + foreach ($this->secondary as $storage) { + $storage->deleteAll($prefix); + } + return TRUE; + } + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function rename($name, $new_name) { + if ($this->storage->rename($name, $new_name)) { + foreach ($this->secondary as $storage) { + $storage->rename($name, $new_name); + } + return TRUE; + } + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function encode($data) { + return $this->storage->encode($data); + } + + /** + * {@inheritdoc} + */ + public function decode($raw) { + return $this->storage->decode($raw); + } + +} diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index 587a9cc..bd6683e 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -249,6 +249,32 @@ */ /** + * Active/runtime configuration storage. + * + * By default, configuration is stored in the {config} database table. To use or + * install with a different storage, override the 'config.storage.active' + * service definition and override the 'bootstrap_config_storage' setting here. + * + * $settings['bootstrap_config_storage'] specifies a callable to instantiate a + * storage that implements \Drupal\Core\Config\StorageInterface. This storage + * must be able to read and return the current 'core.extension' configuration + * before a kernel and service container exists. + * + * Alternatively, you can use the default storage, and additionally write to a + * secondary storage by adding the following in services.yml: + * @code + * services: + * config.storage.file: + * class: Drupal\Core\Config\FileStorage + * factory_class: Drupal\Core\Config\FileStorageFactory + * factory_method: getActive + * tags: + * - { name: 'config.storage.active' } + * @endcode + */ +# $settings['bootstrap_config_storage'] = 'Drupal\Core\Config\BootstrapConfigStorageFactory::getFileStorage'; + +/** * Salt for one-time login links, cancel links, form tokens, etc. * * This variable will be set to a random value by the installer. All one-time @@ -543,19 +569,6 @@ # $cookie_domain = '.example.com'; /** - * Active configuration settings. - * - * By default, the active configuration is stored in the database in the - * {config} table. To install Drupal with a different active configuration - * storage, you need to override the setting here, in addition to overriding - * the config.storage.active service definition in a module or profile. - * - * The 'bootstrap_config_storage' setting needs to be a callable that returns - * core.services.yml. - */ -# $settings['bootstrap_config_storage'] = array('Drupal\Core\Config\BootstrapConfigStorageFactory', 'getFileStorage'); - -/** * Configuration overrides. * * To globally override specific configuration values for this site,