You are here

public function ModerationStateFieldItemList::get in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php \Drupal\content_moderation\Plugin\Field\ModerationStateFieldItemList::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 ItemList::get

File

core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php, line 110

Class

ModerationStateFieldItemList
A computed field that provides a content entity's moderation state.

Namespace

Drupal\content_moderation\Plugin\Field

Code

public function get($index) {
  if ($index !== 0) {
    throw new \InvalidArgumentException('An entity can not have multiple moderation states at the same time.');
  }
  return $this
    ->traitGet($index);
}