diff --git a/core/core.services.yml b/core/core.services.yml index bb65f34..750d7a2 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -85,9 +85,15 @@ services: config.installer: class: Drupal\Core\Config\ConfigInstaller arguments: ['@config.factory', '@config.storage', '@config.typed', '@config.manager', '@event_dispatcher'] + # Primary runtime config storage; injected as dependency into other services. + # Potentially cached. config.storage: alias: config.storage.active + # Actual storage used for runtime configuration; MUST NOT be cached. + # @see \Drupal\Core\DependencyInjection\UpdateServiceProvider config.storage.active: + alias: config.storage.database + config.storage.database: class: Drupal\Core\Config\DatabaseStorage arguments: ['@database', 'config'] config.storage.file: 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..ec58487 --- /dev/null +++ b/core/lib/Drupal/Core/Config/Storage/ChainWriteStorage.php @@ -0,0 +1,151 @@ +storage = $storage; + } + + /** + * Adds a secondary storage to write to. + * + * @param \Drupal\Core\Config\StorageInterface $storage + * The secondary configuration storage to add. + * + * @return $this + */ + public function addStorage(StorageInterface $storage) { + $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..16c50ba 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -249,6 +249,35 @@ */ /** + * Active/runtime configuration storage settings. + * + * By default, the active configuration is stored in the {config} database + * table. To use or install with a different storage, override the + * 'bootstrap_config_storage' setting. + * + * $settings['bootstrap_config_storage'] specifies a callable that instantiates + * a storage class implementing \Drupal\Core\Config\StorageInterface. This + * storage must be able to read and return the current 'core.extension' + * configuration. + * + * In addition, you need to override the 'config.storage.active' service + * definition in services.yml of a profile, module, or the site. + * + * Alternatively, you can use the default storage, and only write to a secondary + * storage, by putting the following into the services.yml file in the site + * directory: + * @code + * services: + * config.storage: + * class: Drupal\Core\Config\Storage\ChainWriteStorage + * arguments: ['@config.storage.active'] + * calls: + * - [addStorage, ['@config.storage.file']] + * @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 +572,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,