function StorageComparer::addChangeList

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Config/StorageComparer.php \Drupal\Core\Config\StorageComparer::addChangeList()
  2. 10 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.

File

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

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.");
    }
  }
}

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