function ImportStorageTransformer::transform

Same name in other branches
  1. 9 core/lib/Drupal/Core/Config/ImportStorageTransformer.php \Drupal\Core\Config\ImportStorageTransformer::transform()
  2. 8.9.x core/lib/Drupal/Core/Config/ImportStorageTransformer.php \Drupal\Core\Config\ImportStorageTransformer::transform()
  3. 10 core/lib/Drupal/Core/Config/ImportStorageTransformer.php \Drupal\Core\Config\ImportStorageTransformer::transform()

Transform the storage to be imported from.

An import transformation is done before the config importer uses the storage to synchronize the configuration. The transformation is also done for displaying differences to review imports. Importing in this context means the active drupal configuration is changed with the ConfigImporter which may or may not be as part of the config synchronization.

Parameters

\Drupal\Core\Config\StorageInterface $storage: The storage to transform for importing from it.

Return value

\Drupal\Core\Config\StorageInterface The transformed storage ready to be imported from.

Throws

\Drupal\Core\Config\StorageTransformerException Thrown when the lock could not be acquired.

File

core/lib/Drupal/Core/Config/ImportStorageTransformer.php, line 94

Class

ImportStorageTransformer
The import storage transformer helps to use the configuration management api.

Namespace

Drupal\Core\Config

Code

public function transform(StorageInterface $storage) {
    // We use a database storage to reduce the memory requirement.
    $mutable = new DatabaseStorage($this->connection, 'config_import');
    if (!$this->persistentLock
        ->lockMayBeAvailable(ConfigImporter::LOCK_NAME)) {
        // If the config importer is already importing, the transformation will
        // always be the one the config importer is already using. This makes sure
        // that even if the storage changes the importer continues importing the
        // same configuration.
        return $mutable;
    }
    // Acquire a lock to ensure that the storage is not changed when a
    // concurrent request tries to transform the storage. The lock will be
    // released at the end of the request.
    if (!$this->requestLock
        ->acquire(self::LOCK_NAME)) {
        $this->requestLock
            ->wait(self::LOCK_NAME);
        if (!$this->requestLock
            ->acquire(self::LOCK_NAME)) {
            throw new StorageTransformerException("Cannot acquire config import transformer lock.");
        }
    }
    // Copy the sync configuration to the created mutable storage.
    self::replaceStorageContents($storage, $mutable);
    // Dispatch the event so that event listeners can alter the configuration.
    $this->eventDispatcher
        ->dispatch(new StorageTransformEvent($mutable), ConfigEvents::STORAGE_TRANSFORM_IMPORT);
    // Return the storage with the altered configuration.
    return $mutable;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.