You are here

protected function StorageComparer::addChangeList in Drupal 9

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

Adds changes to the changelist.

Parameters

string $collection: The storage collection to add changes for.

string $op: The change operation performed. Either delete, create, rename, or update.

array $changes: Array of changes to add to the changelist.

array $sort_order: Array to sort that can be used to sort the changelist. This array must contain all the items that are in the change list.

5 calls to StorageComparer::addChangeList()
StorageComparer::addChangelistCreate in core/lib/Drupal/Core/Config/StorageComparer.php
Creates the create changelist.
StorageComparer::addChangelistDelete in core/lib/Drupal/Core/Config/StorageComparer.php
Creates the delete changelist.
StorageComparer::addChangelistRename in core/lib/Drupal/Core/Config/StorageComparer.php
Creates the rename changelist.
StorageComparer::addChangelistUpdate in core/lib/Drupal/Core/Config/StorageComparer.php
Creates the update changelist.
StorageComparer::moveRenameToUpdate in core/lib/Drupal/Core/Config/StorageComparer.php
Moves a rename operation to an update.

File

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

Class

StorageComparer
Defines a config storage comparer.

Namespace

Drupal\Core\Config

Code

protected function addChangeList($collection, $op, array $changes, array $sort_order = NULL) {

  // Only add changes that aren't already listed.
  $changes = array_diff($changes, $this->changelist[$collection][$op]);
  $this->changelist[$collection][$op] = array_merge($this->changelist[$collection][$op], $changes);
  if (isset($sort_order)) {
    $count = count($this->changelist[$collection][$op]);

    // Sort the changelist in the same order as the $sort_order array and
    // ensure the array is keyed from 0.
    $this->changelist[$collection][$op] = array_values(array_intersect($sort_order, $this->changelist[$collection][$op]));
    if ($count != count($this->changelist[$collection][$op])) {
      throw new \InvalidArgumentException("Sorting the {$op} changelist should not change its length.");
    }
  }
}