function StorageComparer::addChangelistUpdate

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Config/StorageComparer.php \Drupal\Core\Config\StorageComparer::addChangelistUpdate()
  2. 10 core/lib/Drupal/Core/Config/StorageComparer.php \Drupal\Core\Config\StorageComparer::addChangelistUpdate()
  3. 11.x core/lib/Drupal/Core/Config/StorageComparer.php \Drupal\Core\Config\StorageComparer::addChangelistUpdate()

Creates the update changelist.

The list of updates is sorted so that dependencies are created before configuration entities that depend on them. For example, field storages should be updated before fields.

Parameters

string $collection: The storage collection to operate on.

1 call to StorageComparer::addChangelistUpdate()
StorageComparer::createChangelist in core/lib/Drupal/Core/Config/StorageComparer.php

File

core/lib/Drupal/Core/Config/StorageComparer.php, line 253

Class

StorageComparer
Defines a config storage comparer.

Namespace

Drupal\Core\Config

Code

protected function addChangelistUpdate($collection) {
    $recreates = [];
    foreach (array_intersect($this->sourceNames[$collection], $this->targetNames[$collection]) as $name) {
        $source_data = $this->getSourceStorage($collection)
            ->read($name);
        $target_data = $this->getTargetStorage($collection)
            ->read($name);
        if ($source_data !== $target_data) {
            if (isset($source_data['uuid']) && $source_data['uuid'] !== $target_data['uuid']) {
                // The entity has the same file as an existing entity but the UUIDs do
                // not match. This means that the entity has been recreated so config
                // synchronization should do the same.
                $recreates[] = $name;
            }
            else {
                $this->addChangeList($collection, 'update', [
                    $name,
                ]);
            }
        }
    }
    if (!empty($recreates)) {
        // Recreates should become deletes and creates. Deletes should be ordered
        // so that dependencies are deleted first.
        $this->addChangeList($collection, 'create', $recreates, $this->sourceNames[$collection]);
        $this->addChangeList($collection, 'delete', $recreates, array_reverse($this->targetNames[$collection]));
    }
}

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