protected function ConfigSnapshotStorageTrait::getConfigSnapshotStorage in Config Snapshot 8
Returns a configuration snapshot storage service.
Uses a corresponding service if available while falling back to a new storage object. The fallback ensures a storage is provided for a newly- installed extension before the service container is rebuilt.
Parameters
string $snapshot_set: The snapshot set.
string $extension_type: The extension type.
string $extension_name: The extension name.
string $collection: (optional) The collection to store configuration in. Defaults to the default collection.
\Drupal\config_snapshot\Entity\ConfigSnapshot $config_snapshot: (optional) The configuration snapshot.
Return value
\Drupal\config_snapshot\ConfigSnapshotStorage A configuration snapshot storage.
File
- src/
ConfigSnapshotStorageTrait.php, line 35
Class
- ConfigSnapshotStorageTrait
- Provides a utility method for working with configuration snapshot services.
Namespace
Drupal\config_snapshotCode
protected function getConfigSnapshotStorage($snapshot_set, $extension_type, $extension_name, $collection = StorageInterface::DEFAULT_COLLECTION, ConfigSnapshot $config_snapshot = NULL) {
// The service ID is for the default collection.
$service_id = "config_snapshot.{$snapshot_set}.{$extension_type}.{$extension_name}";
if (\Drupal::getContainer() && \Drupal::hasService($service_id)) {
$storage = \Drupal::service($service_id);
// Switch collections if needed.
if ($collection !== StorageInterface::DEFAULT_COLLECTION) {
$storage = $storage
->createCollection($collection);
}
}
else {
$storage = new ConfigSnapshotStorage($snapshot_set, $extension_type, $extension_name, $collection, $config_snapshot);
}
return $storage;
}