3 namespace Drupal\Core\TypedData;
6 * Interface for a list of typed data.
8 * A list of typed data contains only items of the same type, is ordered and may
9 * contain duplicates. Note that the data type of a list is always 'list'.
11 * When implementing this interface which extends Traversable, make sure to list
12 * IteratorAggregate or Iterator before this interface in the implements clause.
14 * @see \Drupal\Core\TypedData\ListDefinitionInterface
18 interface ListInterface extends TraversableTypedDataInterface, \ArrayAccess, \Countable {
21 * Gets the data definition.
23 * @return \Drupal\Core\TypedData\ListDataDefinitionInterface
24 * The data definition object describing the list.
26 public function getDataDefinition();
29 * Determines whether the list contains any non-empty items.
32 * TRUE if the list is empty, FALSE otherwise.
34 public function isEmpty();
37 * Gets the definition of a contained item.
39 * @return \Drupal\Core\TypedData\DataDefinitionInterface
40 * The data definition of contained items.
42 public function getItemDefinition();
45 * Returns the item at the specified position in this list.
48 * Index of the item to return.
50 * @return \Drupal\Core\TypedData\TypedDataInterface|null
51 * The item at the specified position in this list, or NULL if no item
52 * exists at that position.
54 * @throws \Drupal\Core\TypedData\Exception\MissingDataException
55 * If the complex data structure is unset and no item can be created.
57 public function get($index);
60 * Sets the value of the item at a given position in the list.
63 * The position of the item in the list. Since a List only contains
64 * sequential, 0-based indexes, $index has to be:
65 * - Either the position of an existing item in the list. This updates the
67 * - Or the next available position in the sequence of the current list
68 * indexes. This appends a new item with the provided value at the end of
71 * The value of the item to be stored at the specified position.
75 * @throws \InvalidArgumentException
76 * If the $index is invalid (non-numeric, or pointing to an invalid
77 * position in the list).
78 * @throws \Drupal\Core\TypedData\Exception\MissingDataException
79 * If the complex data structure is unset and no item can be set.
81 public function set($index, $value);
84 * Returns the first item in this list.
86 * @return \Drupal\Core\TypedData\TypedDataInterface
87 * The first item in this list.
89 * @throws \Drupal\Core\TypedData\Exception\MissingDataException
90 * If the complex data structure is unset and no item can be created.
92 public function first();
95 * Appends a new item to the list.
98 * The value of the new item.
100 * @return \Drupal\Core\TypedData\TypedDataInterface
101 * The item that was appended.
103 public function appendItem($value = NULL);
106 * Removes the item at the specified position.
109 * Index of the item to remove.
113 public function removeItem($index);
116 * Filters the items in the list using a custom callback.
118 * @param callable $callback
119 * The callback to use for filtering. Like with array_filter(), the
120 * callback is called for each item in the list. Only items for which the
121 * callback returns TRUE are preserved.
125 public function filter($callback);