You are here

public function ConfigSyncSnapshotter::refreshExtensionSnapshot in Configuration Synchronizer 8.2

Takes a snapshot of configuration from specified modules or themes.

Two modes are supported: install and import. Install mode is invoked when an extension is initially installed, while import mode is invoked on subsequent import of configuration updates.

The distinction between install and import modes has implications for the handling of extension-provided configuration alters. Alters are considered to be "owned" by the extension that provides them. On install, existing snapshots should be altered only the newly-installed module or modules. This approach ensures the snapshot mirrors the installed state of the extension-provided configuration. In contrast, on import, alters should be applied from all installed modules.

Parameters

string $type: The type of extension to snapshot.

array $names: An array of extension names.

string $mode: The snapshot mode. Valid values are:

Overrides ConfigSyncSnapshotterInterface::refreshExtensionSnapshot

1 call to ConfigSyncSnapshotter::refreshExtensionSnapshot()
ConfigSyncSnapshotter::createSnapshot in src/ConfigSyncSnapshotter.php
Takes a snapshot of configuration from all installed modules and themes.

File

src/ConfigSyncSnapshotter.php, line 98

Class

ConfigSyncSnapshotter
The ConfigSyncSnapshotter provides helper functions for taking snapshots of extension-provided configuration.

Namespace

Drupal\config_sync

Code

public function refreshExtensionSnapshot($type, array $names, $mode) {
  foreach ($names as $name) {
    $extensions = [];
    $pathname = $this
      ->drupalGetFilename($type, $name);
    $extensions[$name] = new Extension($this->root, $type, $pathname);
    $snapshot_storage = $this
      ->getConfigSnapshotStorage(ConfigSyncSnapshotterInterface::CONFIG_SNAPSHOT_SET, $type, $name);
    switch ($mode) {

      // On install, snapshot configuration in two stages. First, snapshot
      // unaltered configuration. Then, below, apply alters.
      case ConfigSyncSnapshotterInterface::SNAPSHOT_MODE_INSTALL:
        $this->configCollector
          ->addConfigForSnapshotting($extensions);
        break;

      // On import, snapshot fully altered configuration.
      case ConfigSyncSnapshotterInterface::SNAPSHOT_MODE_IMPORT:
        $this->configCollector
          ->addInstallableConfig($extensions);
        break;
    }

    // Create the snapshot.
    $this->configManager
      ->createSnapshot($this->providerStorage, $snapshot_storage);

    // Conditionally alter the previously added configuration.
    if ($mode === ConfigSyncSnapshotterInterface::SNAPSHOT_MODE_INSTALL) {
      $this->configCollector
        ->alterConfigSnapshots($extensions);
    }
  }
  $this
    ->snapshotNewItems();
}