function ItemList::rekey
Same name in other branches
- 9 core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php \Drupal\Core\TypedData\Plugin\DataType\ItemList::rekey()
- 10 core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php \Drupal\Core\TypedData\Plugin\DataType\ItemList::rekey()
- 11.x 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 155
Class
- ItemList
- A generic list class.
Namespace
Drupal\Core\TypedData\Plugin\DataTypeCode
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);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.