You are here

public function ComputedItemListTrait::get in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php \Drupal\Core\TypedData\ComputedItemListTrait::get()
1 call to ComputedItemListTrait::get()
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/ComputedItemListTrait.php, line 69

Class

ComputedItemListTrait
Provides common functionality for computed item lists.

Namespace

Drupal\Core\TypedData

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

  // Unlike the base implementation of
  // \Drupal\Core\TypedData\ListInterface::get(), we do not add an empty item
  // automatically because computed item lists need to behave like
  // non-computed ones. For example, calling isEmpty() on a computed item list
  // should return TRUE when the values were computed and the item list is
  // truly empty.
  // @see \Drupal\Core\TypedData\Plugin\DataType\ItemList::get().
  $this
    ->ensureComputedValue();
  return isset($this->list[$index]) ? $this->list[$index] : NULL;
}