You are here

public function ItemList::get 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::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.

Throws

\Drupal\Core\TypedData\Exception\MissingDataException If the complex data structure is unset and no item can be created.

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 isset($this->list[$index]) ? $this->list[$index] : NULL;
}