interface ListInterface
Same name in other branches
- 9 core/lib/Drupal/Core/TypedData/ListInterface.php \Drupal\Core\TypedData\ListInterface
- 8.9.x core/lib/Drupal/Core/TypedData/ListInterface.php \Drupal\Core\TypedData\ListInterface
- 10 core/lib/Drupal/Core/TypedData/ListInterface.php \Drupal\Core\TypedData\ListInterface
Interface for a list of typed data.
A list of typed data contains only items of the same type, is ordered and may contain duplicates. Note that the data type of a list is always 'list'.
When implementing this interface which extends Traversable, make sure to list IteratorAggregate or Iterator before this interface in the implements clause.
Hierarchy
- interface \Drupal\Core\TypedData\TypedDataInterface
- interface \Drupal\Core\TypedData\TraversableTypedDataInterface extends \Drupal\Core\TypedData\TypedDataInterface \Drupal\Core\TypedData\Traversable
- interface \Drupal\Core\TypedData\ListInterface extends \Drupal\Core\TypedData\TraversableTypedDataInterface \Drupal\Core\TypedData\ArrayAccess \Drupal\Core\TypedData\Countable
- interface \Drupal\Core\TypedData\TraversableTypedDataInterface extends \Drupal\Core\TypedData\TypedDataInterface \Drupal\Core\TypedData\Traversable
Expanded class hierarchy of ListInterface
All classes that implement ListInterface
See also
\Drupal\Core\TypedData\ListDefinitionInterface
Related topics
7 files declare their use of ListInterface
- EntityFieldTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityFieldTest.php - FieldItemListInterface.php in core/
lib/ Drupal/ Core/ Field/ FieldItemListInterface.php - IsNullConstraintValidator.php in core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ IsNullConstraintValidator.php - ItemList.php in core/
lib/ Drupal/ Core/ TypedData/ Plugin/ DataType/ ItemList.php - ListNormalizer.php in core/
modules/ serialization/ src/ Normalizer/ ListNormalizer.php
File
-
core/
lib/ Drupal/ Core/ TypedData/ ListInterface.php, line 18
Namespace
Drupal\Core\TypedDataView source
interface ListInterface extends TraversableTypedDataInterface, \ArrayAccess, \Countable {
/**
* Gets the data definition.
*
* @return \Drupal\Core\TypedData\ListDataDefinitionInterface
* The data definition object describing the list.
*/
public function getDataDefinition();
/**
* Determines whether the list contains any non-empty items.
*
* @return bool
* TRUE if the list is empty, FALSE otherwise.
*/
public function isEmpty();
/**
* Gets the definition of a contained item.
*
* @return \Drupal\Core\TypedData\DataDefinitionInterface
* The data definition of contained items.
*/
public function getItemDefinition();
/**
* Returns the item at the specified position in this list.
*
* @param int $index
* Index of the item to return.
*
* @return \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.
*/
public function get($index);
/**
* Sets the value of the item at a given position in the list.
*
* @param int $index
* The position of the item in the list. Since a List only contains
* sequential, 0-based indexes, $index has to be:
* - Either the position of an existing item in the list. This updates the
* item value.
* - Or the next available position in the sequence of the current list
* indexes. This appends a new item with the provided value at the end of
* the list.
* @param mixed $value
* The value of the item to be stored at the specified position.
*
* @return $this
*
* @throws \InvalidArgumentException
* If the $index is invalid (non-numeric, or pointing to an invalid
* position in the list).
* @throws \Drupal\Core\TypedData\Exception\MissingDataException
* If the complex data structure is unset and no item can be set.
*/
public function set($index, $value);
/**
* Returns the first item in this list.
*
* @return \Drupal\Core\TypedData\TypedDataInterface|null
* The first item in this list, or NULL if there are no items.
*
* @throws \Drupal\Core\TypedData\Exception\MissingDataException
* If the complex data structure is unset and no item can be created.
*/
public function first();
/**
* Appends a new item to the list.
*
* @param mixed $value
* The value of the new item.
*
* @return \Drupal\Core\TypedData\TypedDataInterface
* The item that was appended.
*/
public function appendItem($value = NULL);
/**
* Removes the item at the specified position.
*
* @param int $index
* Index of the item to remove.
*
* @return $this
*/
public function removeItem($index);
/**
* Filters the items in the list using a custom callback.
*
* @param callable $callback
* The callback to use for filtering. Like with array_filter(), the
* callback is called for each item in the list. Only items for which the
* callback returns TRUE are preserved.
*
* @return $this
*/
public function filter($callback);
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
ListInterface::appendItem | public | function | Appends a new item to the list. | 1 | |
ListInterface::filter | public | function | Filters the items in the list using a custom callback. | 1 | |
ListInterface::first | public | function | Returns the first item in this list. | 1 | |
ListInterface::get | public | function | Returns the item at the specified position in this list. | 1 | |
ListInterface::getDataDefinition | public | function | Gets the data definition. | Overrides TypedDataInterface::getDataDefinition | |
ListInterface::getItemDefinition | public | function | Gets the definition of a contained item. | 1 | |
ListInterface::isEmpty | public | function | Determines whether the list contains any non-empty items. | 1 | |
ListInterface::removeItem | public | function | Removes the item at the specified position. | 1 | |
ListInterface::set | public | function | Sets the value of the item at a given position in the list. | 1 | |
TraversableTypedDataInterface::onChange | public | function | React to changes to a child property or item. | 4 | |
TypedDataInterface::applyDefaultValue | public | function | Applies the default value. | 1 | |
TypedDataInterface::createInstance | public static | function | Constructs a TypedData object given its definition and context. | 1 | |
TypedDataInterface::getConstraints | public | function | Gets a list of validation constraints. | 1 | |
TypedDataInterface::getName | public | function | Returns the name of a property or item. | 1 | |
TypedDataInterface::getParent | public | function | Returns the parent data structure; i.e. either complex data or a list. | 1 | |
TypedDataInterface::getPropertyPath | public | function | Returns the property path of the data. | 1 | |
TypedDataInterface::getRoot | public | function | Returns the root of the typed data tree. | 1 | |
TypedDataInterface::getString | public | function | Returns a string representation of the data. | 1 | |
TypedDataInterface::getValue | public | function | Gets the data value. | 1 | |
TypedDataInterface::setContext | public | function | Sets the context of a property or item via a context aware parent. | 1 | |
TypedDataInterface::setValue | public | function | Sets the data value. | 1 | |
TypedDataInterface::validate | public | function | Validates the currently set data value. | 1 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.