interface ComplexDataInterface implements TraversableTypedDataInterface (View source)

Interface for complex data; i.e. data containing named and typed properties.

The name of a property has to be a valid PHP variable name, starting with an alphabetic character.

This is implemented by entities as well as by field item classes of entities.

When implementing this interface which extends Traversable, make sure to list IteratorAggregate or Iterator before this interface in the implements clause.

Methods

static 
createInstance(DataDefinitionInterface $definition, string|null $name = NULL, TraversableTypedDataInterface $parent = NULL)

Constructs a TypedData object given its definition and context.

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.

getParent()

Returns the parent data structure; i.e. either complex data or a list.

getRoot()

Returns the root of the typed data tree.

string
getPropertyPath()

Returns the property path of the data.

setContext(string|null $name = NULL, TraversableTypedDataInterface $parent = NULL)

Sets the context of a property or item via a context aware parent.

onChange($name)

React to changes to a child property or item.

get($property_name)

Gets a property object.

$this
set($property_name, $value, bool $notify = TRUE)

Sets a property value.

getProperties(bool $include_computed = FALSE)

Gets an array of property objects.

array
toArray()

Returns an array of all property values.

bool
isEmpty()

Determines whether the data structure is empty.

Details

static createInstance(DataDefinitionInterface $definition, string|null $name = NULL, TraversableTypedDataInterface $parent = NULL)

Constructs a TypedData object given its definition and context.

When \Drupal\Core\Config\TypedConfigManager has been fixed to use class-based definitions, type-hint $definition to DataDefinitionInterface. https://www.drupal.org/node/1928868

Parameters

DataDefinitionInterface $definition

The data definition.

string|null $name

(optional) The name of the created property, or NULL if it is the root of a typed data tree. Defaults to NULL.

TraversableTypedDataInterface $parent

(optional) The parent object of the data property, or NULL if it is the root of a typed data tree. Defaults to NULL.

See also

TypedDataManager::create

DataDefinitionInterface getDataDefinition()

Gets the data definition.

Return Value

DataDefinitionInterface

The data definition object.

mixed getValue()

Gets the data value.

Return Value

mixed

The data value.

setValue(mixed|null $value, bool $notify = TRUE)

Sets the data value.

Parameters

mixed|null $value

The value to set in the format as documented for the data type or NULL to unset the data value.

bool $notify

(optional) Whether to notify the parent object of the change. Defaults to TRUE. If a property is updated from a parent object, set it to FALSE to avoid being notified again.

Exceptions

InvalidArgumentException
ReadOnlyException

string getString()

Returns a string representation of the data.

Return Value

string

The string representation of the data.

array getConstraints()

Gets a list of validation constraints.

Return Value

array

Array of constraints, each being an instance of \Symfony\Component\Validator\Constraint.

ConstraintViolationListInterface validate()

Validates the currently set data value.

Return Value

ConstraintViolationListInterface

A list of constraint violations. If the list is empty, validation succeeded.

$this applyDefaultValue(bool $notify = TRUE)

Applies the default value.

Parameters

bool $notify

(optional) Whether to notify the parent object of the change. Defaults to TRUE. If a property is updated from a parent object, set it to FALSE to avoid being notified again.

Return Value

$this

Returns itself to allow for chaining.

string|int|null getName()

Returns the name of a property or item.

Return Value

string|int|null

If the data is a property of some complex data, the name of the property. If the data is an item of a list, the name is the numeric position of the item in the list, starting with 0. Otherwise, NULL is returned.

TraversableTypedDataInterface|null getParent()

Returns the parent data structure; i.e. either complex data or a list.

Return Value

TraversableTypedDataInterface|null

The parent data structure, either complex data or a list; or NULL if this is the root of the typed data tree.

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.

Return Value

TraversableTypedDataInterface

The root data structure, either complex data or a list.

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'.

Return Value

string

The property path relative to the root of the typed tree, or an empty string if this is the root.

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.

Parameters

string|null $name

(optional) The name of the property or the delta of the list item, or NULL if it is the root of a typed data tree. Defaults to NULL.

TraversableTypedDataInterface $parent

(optional) The parent object of the data property, or NULL if it is the root of a typed data tree. Defaults to NULL.

onChange($name)

React to changes to a child property or item.

Note that this is invoked after any changes have been applied.

Parameters

$name

The name of the property or the delta of the list item which is changed.

TypedDataInterface get($property_name)

Gets a property object.

Parameters

$property_name

The name of the property to get; e.g., 'title' or 'name'.

Return Value

TypedDataInterface

The property object.

Exceptions

InvalidArgumentException
MissingDataException

$this set($property_name, $value, bool $notify = TRUE)

Sets a property value.

Parameters

$property_name

The name of the property to set; e.g., 'title' or 'name'.

$value

The value to set, or NULL to unset the property.

bool $notify

(optional) Whether to notify the parent object of the change. Defaults to TRUE. If the update stems from a parent object, set it to FALSE to avoid being notified again.

Return Value

$this

Exceptions

InvalidArgumentException
MissingDataException

TypedDataInterface[] getProperties(bool $include_computed = FALSE)

Gets an array of property objects.

Parameters

bool $include_computed

If set to TRUE, computed properties are included. Defaults to FALSE.

Return Value

TypedDataInterface[]

An array of property objects implementing the TypedDataInterface, keyed by property name.

Exceptions

MissingDataException

array toArray()

Returns an array of all property values.

Gets an array of plain property values including all not-computed properties.

Return Value

array

An array of property values, keyed by property name.

Exceptions

MissingDataException

bool isEmpty()

Determines whether the data structure is empty.

Return Value

bool

TRUE if the data structure is empty, FALSE otherwise.