By bircher on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.7.x
Introduced in version:
8.7.0-alpha1
Issue links:
Description:
When copying configuration from one storage to another a developer previously had to be careful to include all collections and make sure the destination storage doesn't contain any previous configuration.
Now classes that need to make sure two storages contain the same configuration can use the Drupal\Core\Config\StorageCopyTrait.
Note that this is intended for operations like configuration export. Do NOT use the active configuration storage as the destination. Updating the active configuration should always be done via the ConfigImporter or via an API that saves configuration entities or objects.
An example usage is:
use Drupal\Core\Config\MemoryStorage;
use \Drupal\Core\Config\StorageCopyTrait;
class A {
use StorageCopyTrait;
public function doSomethingAwesome() {
$myStorage = new MemoryStorage();
// Fill the storage with the contents of the sync storage.
static::replaceStorageContents(\Drupal::service('config.storage.sync'), $myStorage);
// Do something with the storage
$myStorage->deleteAll('my_module');
$myStorage->write('my_module.settings', ['example' => 'true']);
// Reset $myStorage to be the same as the sync storage again.
static::replaceStorageContents(\Drupal::service('config.storage.sync'), $myStorage);
}
}
Impacts:
Module developers