You are here

protected function ConfigSnapshotStorage::setConfigSnapshot in Config Snapshot 8

Sets the config snapshot object associated with an extension.

The function reads the config_snapshot object from the current configuration, or returns a ready-to-use empty one if no configuration entry exists yet for the extension.

1 call to ConfigSnapshotStorage::setConfigSnapshot()
ConfigSnapshotStorage::__construct in src/ConfigSnapshotStorage.php
Constructs a new ConfigSnapshotStorage.

File

src/ConfigSnapshotStorage.php, line 81

Class

ConfigSnapshotStorage
Provides a configuration storage saved as simple configuration.

Namespace

Drupal\config_snapshot

Code

protected function setConfigSnapshot($config_snapshot) {
  if (is_null($config_snapshot)) {

    // Try loading the snapshot from configuration.
    $config_snapshot = ConfigSnapshot::load("{$this->snapshotSet}.{$this->extensionType}.{$this->extensionName}");

    // If not found, create a fresh snapshot object.
    if (!$config_snapshot) {
      $config_snapshot = ConfigSnapshot::create([
        'snapshotSet' => $this->snapshotSet,
        'extensionType' => $this->extensionType,
        'extensionName' => $this->extensionName,
      ]);
    }
  }
  $this->configSnapshot = $config_snapshot;
}