abstract class ArrayElement extends Element implements IteratorAggregate, TypedConfigInterface, ComplexDataInterface (View source)

Defines a generic configuration element that contains multiple properties.

Traits

Provides dependency injection friendly methods for serialization.

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Wrapper methods for classes that needs typed data manager object.

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected TypedDataManagerInterface $typedDataManager

The typed data manager used for creating the data types.

from  TypedDataTrait
protected DataDefinitionInterface $definition

The data definition.

from  TypedData
protected string $name

The property name.

from  TypedData
protected TraversableTypedDataInterface|null $parent

The parent typed data object.

from  TypedData
protected mixed $value

The configuration value.

from  Element
protected $elements

Parsed elements.

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

$this
setTypedDataManager(TypedDataManagerInterface $typed_data_manager)

Sets the typed data manager.

getTypedDataManager()

Gets the typed data manager.

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

Constructs a TypedData object given its definition and context.

__construct(DataDefinitionInterface $definition, string $name = NULL, TypedDataInterface $parent = NULL)

Constructs a TypedData object given its definition and context.

string
getPluginId()

Gets the plugin_id of the plugin instance.

array
getPluginDefinition()

Gets the definition of the plugin implementation.

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.

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

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

string|int|null
getName()

Returns the name of a property or item.

getRoot()

Returns the root of the typed data tree.

string
getPropertyPath()

Returns the property path of the data.

getParent()

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

array
getAllKeys()

Gets valid configuration data keys.

parse()

Builds an array of contained elements.

getElementDefinition(int|string $key)

Gets data definition object for contained element.

get($name)

Gets a contained typed configuration element.

array
getElements()

Gets an array of contained elements.

bool
isEmpty()

Determines whether the data structure is empty.

array
toArray()

Returns an array of all property values.

onChange($name)

React to changes to a child property or item.

getIterator()

{@inheritdoc}

createElement(DataDefinitionInterface $definition, mixed $value, string $key)

Creates a contained typed configuration object.

buildDataDefinition(array $definition, $value, string $key)

Creates a new data definition object from a type definition array and actual configuration data.

bool
isNullable()

Determines if this element allows NULL as a value.

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

Sets a property value.

getProperties(bool $include_computed = FALSE)

Gets an array of property objects.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

$this setTypedDataManager(TypedDataManagerInterface $typed_data_manager)

Sets the typed data manager.

Parameters

TypedDataManagerInterface $typed_data_manager

The typed data manager.

Return Value

$this

TypedDataManagerInterface getTypedDataManager()

Gets the typed data manager.

Return Value

TypedDataManagerInterface

The typed data manager.

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

Constructs a TypedData object given its definition and context.

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.

__construct(DataDefinitionInterface $definition, string $name = NULL, TypedDataInterface $parent = NULL)

Constructs a TypedData object given its definition and context.

Parameters

DataDefinitionInterface $definition

The data definition.

string $name

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

TypedDataInterface $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

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

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.

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.

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

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.

protected array getAllKeys()

Gets valid configuration data keys.

Return Value

array

Array of valid configuration data keys.

protected TypedDataInterface[] parse()

Builds an array of contained elements.

Return Value

TypedDataInterface[]

An array of elements contained in this element.

abstract protected DataDefinitionInterface getElementDefinition(int|string $key)

Gets data definition object for contained element.

Parameters

int|string $key

Property name or index of the element.

Return Value

DataDefinitionInterface

TypedDataInterface get($name)

Gets a contained typed configuration element.

Parameters

$name

The name of the property to get; e.g., 'title' or 'name'. Nested elements can be get using multiple dot delimited names, for example, 'page.front'.

Return Value

TypedDataInterface

The property object.

Exceptions

InvalidArgumentException

array getElements()

Gets an array of contained elements.

Return Value

array

Array of \Drupal\Core\TypedData\TypedDataInterface objects.

bool isEmpty()

Determines whether the data structure is empty.

Return Value

bool

TRUE if the data structure is empty, FALSE otherwise.

array toArray()

Returns an array of all property values.

Return Value

array

An array of property values, keyed by property name.

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.

getIterator()

{@inheritdoc}

protected TypedDataInterface createElement(DataDefinitionInterface $definition, mixed $value, string $key)

Creates a contained typed configuration object.

Parameters

DataDefinitionInterface $definition

The data definition object.

mixed $value

(optional) The data value. If set, it has to match one of the supported data type format as documented for the data type classes.

string $key

The key of the contained element.

Return Value

TypedDataInterface

protected DataDefinitionInterface buildDataDefinition(array $definition, $value, string $key)

Creates a new data definition object from a type definition array and actual configuration data.

Parameters

array $definition

The base type definition array, for which a data definition should be created.

$value

The value of the configuration element.

string $key

The key of the contained element.

Return Value

DataDefinitionInterface

bool isNullable()

Determines if this element allows NULL as a value.

Return Value

bool

TRUE if NULL is a valid value, FALSE otherwise.

$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