function ItemList::get

Same name in other branches
  1. 9 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()

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 96

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.');
    }
    // Automatically create the first item for computed fields.
    // @deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0.
    // Use \Drupal\Core\TypedData\ComputedItemListTrait instead.
    if ($index == 0 && !isset($this->list[0]) && $this->definition
        ->isComputed()) {
        @trigger_error('Automatically creating the first item for computed fields is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. Use \\Drupal\\Core\\TypedData\\ComputedItemListTrait instead.', E_USER_DEPRECATED);
        $this->list[0] = $this->createItem(0);
    }
    return isset($this->list[$index]) ? $this->list[$index] : NULL;
}

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