You are here

protected function StorageComparer::addChangelistRename in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Config/StorageComparer.php \Drupal\Core\Config\StorageComparer::addChangelistRename()
  2. 9 core/lib/Drupal/Core/Config/StorageComparer.php \Drupal\Core\Config\StorageComparer::addChangelistRename()

Creates the rename changelist.

The list of renames is created from the different source and target names with same UUID. These changes will be removed from the create and delete lists.

Parameters

string $collection: The storage collection to operate on.

File

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

Class

StorageComparer
Defines a config storage comparer.

Namespace

Drupal\Core\Config

Code

protected function addChangelistRename($collection) {

  // Renames will be present in both the create and delete lists.
  $create_list = $this
    ->getChangelist('create', $collection);
  $delete_list = $this
    ->getChangelist('delete', $collection);
  if (empty($create_list) || empty($delete_list)) {
    return;
  }
  $create_uuids = [];
  foreach ($this->sourceNames[$collection] as $name) {
    $data = $this
      ->getSourceStorage($collection)
      ->read($name);
    if (isset($data['uuid']) && in_array($name, $create_list)) {
      $create_uuids[$data['uuid']] = $name;
    }
  }
  if (empty($create_uuids)) {
    return;
  }
  $renames = [];

  // Renames should be ordered so that dependencies are renamed last. This
  // ensures that if there is logic in the configuration entity class to keep
  // names in sync it will still work. $this->targetNames is in the desired
  // order due to the use of configuration dependencies in
  // \Drupal\Core\Config\StorageComparer::getAndSortConfigData().
  // Node type is a good example of a configuration entity that renames other
  // configuration when it is renamed.
  // @see \Drupal\node\Entity\NodeType::postSave()
  foreach ($this->targetNames[$collection] as $name) {
    $data = $this
      ->getTargetStorage($collection)
      ->read($name);
    if (isset($data['uuid']) && isset($create_uuids[$data['uuid']])) {

      // Remove the item from the create list.
      $this
        ->removeFromChangelist($collection, 'create', $create_uuids[$data['uuid']]);

      // Remove the item from the delete list.
      $this
        ->removeFromChangelist($collection, 'delete', $name);

      // Create the rename name.
      $renames[] = $this
        ->createRenameName($name, $create_uuids[$data['uuid']]);
    }
  }
  $this
    ->addChangeList($collection, 'rename', $renames);
}