You are here

protected function ItemList::rekey in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php \Drupal\Core\TypedData\Plugin\DataType\ItemList::rekey()
  2. 10 core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php \Drupal\Core\TypedData\Plugin\DataType\ItemList::rekey()

Renumbers the items in the list.

Parameters

int $from_index: Optionally, the index at which to start the renumbering, if it is known that items before that can safely be skipped (for example, when removing an item at a given index).

2 calls to ItemList::rekey()
ItemList::filter in core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php
Filters the items in the list using a custom callback.
ItemList::removeItem in core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php
Removes the item at the specified position.

File

core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php, line 151

Class

ItemList
A generic list class.

Namespace

Drupal\Core\TypedData\Plugin\DataType

Code

protected function rekey($from_index = 0) {

  // Re-key the list to maintain consecutive indexes.
  $this->list = array_values($this->list);

  // Each item holds its own index as a "name", it needs to be updated
  // according to the new list indexes.
  for ($i = $from_index; $i < count($this->list); $i++) {
    $this->list[$i]
      ->setContext($i, $this);
  }
}