protected function StorageComparer::addChangelistRename

protected StorageComparer::addChangelistRename($collection)

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 293

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 = array();
  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 = array();

  // 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);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Config!StorageComparer.php/function/StorageComparer::addChangelistRename/8.1.x