function ItemList::get

Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php \Drupal\Core\TypedData\Plugin\DataType\ItemList::get()
  2. 10 core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php \Drupal\Core\TypedData\Plugin\DataType\ItemList::get()
  3. 11.x core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php \Drupal\Core\TypedData\Plugin\DataType\ItemList::get()

Returns the item at the specified position in this list.

Parameters

int $index: Index of the item to return.

Return value

\Drupal\Core\TypedData\TypedDataInterface|null The item at the specified position in this list, or NULL if no item exists at that position.

Overrides ListInterface::get

3 calls to ItemList::get()
CommentFieldItemList::get in core/modules/comment/src/CommentFieldItemList.php
Returns the item at the specified position in this list.
ItemList::first in core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php
Returns the first item in this list.
ItemList::offsetGet in core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php
2 methods override ItemList::get()
CommentFieldItemList::get in core/modules/comment/src/CommentFieldItemList.php
Returns the item at the specified position in this list.
ModerationStateFieldItemList::get in core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php
Returns the item at the specified position in this list.

File

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

Class

ItemList
A generic list class.

Namespace

Drupal\Core\TypedData\Plugin\DataType

Code

public function get($index) {
    if (!is_numeric($index)) {
        throw new \InvalidArgumentException('Unable to get a value with a non-numeric delta in a list.');
    }
    return $this->list[$index] ?? NULL;
}

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