FieldItemListInterface
interface FieldItemListInterface implements ListInterface, AccessibleInterface (View source)
Interface for fields, being lists of field items.
This interface must be implemented by every entity field, whereas contained field items must implement the FieldItemInterface. Some methods of the fields are delegated to the first contained item, in particular get() and set() as well as their magic equivalences.
Optionally, a typed data object implementing Drupal\Core\TypedData\TypedDataInterface may be passed to ArrayAccess::offsetSet() instead of a plain value.
When implementing this interface which extends Traversable, make sure to list IteratorAggregate or Iterator before this interface in the implements clause.
Methods
Constructs a TypedData object given its definition and context.
Validates the currently set data value.
Returns the parent data structure; i.e. either complex data or a list.
Returns the root of the typed data tree.
Sets the context of a property or item via a context aware parent.
Gets the definition of a contained item.
Returns the item at the specified position in this list.
Sets the value of the item at a given position in the list.
Appends a new item to the list.
Filters the items in the list using a custom callback.
Checks data value access.
Gets the entity that field belongs to.
Sets the langcode of the field values held in the object.
Gets the langcode of the field values held in the object.
Gets the field definition.
Returns the array of field settings.
Returns the value of a given field setting.
Contains the default access logic of this field.
Filters out empty field items and re-numbers the item deltas.
Magic method: Gets a property value of to the first field item.
Magic method: Sets a property value of the first field item.
Magic method: Determines whether a property of the first field item is set.
Magic method: Unsets a property of the first field item.
Defines custom presave behavior for field values.
Defines custom post-save behavior for field values.
Defines custom delete behavior for field values.
Defines custom revision delete behavior for field values.
Returns a renderable array for the field items.
Populates a specified number of field items with valid sample data.
Returns a form for the default value input.
Validates the submitted default value.
Processes the submitted default value.
Processes the default value before being applied.
Determines equality to another object implementing FieldItemListInterface.
Determines whether the field has relevant changes.
Details
static
createInstance(DataDefinitionInterface $definition, string|null $name = NULL, TraversableTypedDataInterface $parent = NULL)
Constructs a TypedData object given its definition and context.
DataDefinitionInterface
getDataDefinition()
Gets the data definition.
mixed
getValue()
Gets the data value.
setValue(mixed|null $value, bool $notify = TRUE)
Sets the data value.
string
getString()
Returns a string representation of the data.
array
getConstraints()
Gets a list of validation constraints.
ConstraintViolationListInterface
validate()
Validates the currently set data value.
$this
applyDefaultValue(bool $notify = TRUE)
Applies the default value.
string|int|null
getName()
Returns the name of a property or item.
TraversableTypedDataInterface|null
getParent()
Returns the parent data structure; i.e. either complex data or a list.
TraversableTypedDataInterface
getRoot()
Returns the root of the typed data tree.
Returns the root data for a tree of typed data objects; e.g. for an entity field item the root of the tree is its parent entity object.
string
getPropertyPath()
Returns the property path of the data.
The trail of property names relative to the root of the typed data tree, separated by dots; e.g. 'field_text.0.format'.
setContext(string|null $name = NULL, TraversableTypedDataInterface $parent = NULL)
Sets the context of a property or item via a context aware parent.
This method is supposed to be called by the factory only.
onChange($name)
React to changes to a child property or item.
Note that this is invoked after any changes have been applied.
bool
isEmpty()
Determines whether the list contains any non-empty items.
DataDefinitionInterface
getItemDefinition()
Gets the definition of a contained item.
TypedDataInterface|null
get(int $index)
Returns the item at the specified position in this list.
$this
set(int $index, mixed $value)
Sets the value of the item at a given position in the list.
TypedDataInterface|null
first()
Returns the first item in this list.
TypedDataInterface
appendItem(mixed $value = NULL)
Appends a new item to the list.
$this
removeItem(int $index)
Removes the item at the specified position.
$this
filter(callable $callback)
Filters the items in the list using a custom callback.
bool|AccessResultInterface
access(string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)
Checks data value access.
FieldableEntityInterface
getEntity()
Gets the entity that field belongs to.
setLangcode(string $langcode)
Sets the langcode of the field values held in the object.
string
getLangcode()
Gets the langcode of the field values held in the object.
FieldDefinitionInterface
getFieldDefinition()
Gets the field definition.
array
getSettings()
Returns the array of field settings.
mixed
getSetting(string $setting_name)
Returns the value of a given field setting.
AccessResultInterface
defaultAccess($operation = 'view', AccountInterface $account = NULL)
Contains the default access logic of this field.
See \Drupal\Core\Entity\EntityAccessControlHandlerInterface::fieldAccess() for the parameter documentation.
$this
filterEmptyItems()
Filters out empty field items and re-numbers the item deltas.
__get($property_name)
Magic method: Gets a property value of to the first field item.
__set($property_name, $value)
Magic method: Sets a property value of the first field item.
__isset($property_name)
Magic method: Determines whether a property of the first field item is set.
__unset($property_name)
Magic method: Unsets a property of the first field item.
preSave()
Defines custom presave behavior for field values.
This method is called during the process of saving an entity, just before item values are written into storage.
bool
postSave(bool $update)
Defines custom post-save behavior for field values.
This method is called during the process of saving an entity, just after item values are written into storage.
delete()
Defines custom delete behavior for field values.
This method is called during the process of deleting an entity, just before values are deleted from storage.
deleteRevision()
Defines custom revision delete behavior for field values.
This method is called from during the process of deleting an entity revision, just before the field values are deleted from storage. It is only called for entity types that support revisioning.
array
view(string|array $display_options = [])
Returns a renderable array for the field items.
generateSampleItems(int $count = 1)
Populates a specified number of field items with valid sample data.
array
defaultValuesForm(array $form, FormStateInterface $form_state)
Returns a form for the default value input.
Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure instance-level default value.
defaultValuesFormValidate(array $element, array $form, FormStateInterface $form_state)
Validates the submitted default value.
Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure instance-level default value.
array
defaultValuesFormSubmit(array $element, array $form, FormStateInterface $form_state)
Processes the submitted default value.
Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure instance-level default value.
static array
processDefaultValue(array $default_value, FieldableEntityInterface $entity, FieldDefinitionInterface $definition)
Processes the default value before being applied.
Defined or configured default values of a field might need some processing in order to be a valid runtime value for the field type; e.g., a date field could process the defined value of 'NOW' to a valid date.
bool
equals(FieldItemListInterface $list_to_compare)
Determines equality to another object implementing FieldItemListInterface.
This method is usually used by the storage to check for not computed value changes, which will be saved into the storage.
bool
hasAffectingChanges(FieldItemListInterface $original_items, string $langcode)
Determines whether the field has relevant changes.
This is for example used to determine if a revision of an entity has changes in a given translation. Unlike \Drupal\Core\Field\FieldItemListInterface::equals(), this can report that for example an untranslatable field, despite being changed and therefore technically affecting all translations, is only internal metadata or only affects a single translation.