interface ComplexDataDefinitionInterface implements DataDefinitionInterface (View source)

Interface for complex data definitions.

Methods

createFromDataType(string $data_type)

Creates a new data definition object.

string
getDataType()

Returns the data type of the data.

getLabel()

Returns a human readable label.

string|null
getDescription()

Returns a human readable description.

bool
isList()

Returns whether the data is multi-valued, i.e. a list of data items.

bool
isReadOnly()

Determines whether the data is read-only.

bool
isComputed()

Determines whether the data value is computed.

bool
isRequired()

Determines whether a data value is required.

string
getClass()

Returns the class used for creating the typed data object.

array
getSettings()

Returns the array of settings, as required by the used class.

mixed
getSetting(string $setting_name)

Returns the value of a given setting.

array[]
getConstraints()

Returns an array of validation constraints.

array
getConstraint(string $constraint_name)

Returns a validation constraint.

addConstraint(string $constraint_name, array|null $options = NULL)

Adds a validation constraint.

bool
isInternal()

Determines whether the data value is internal.

getPropertyDefinition(string $name)

Gets the definition of a contained property.

getPropertyDefinitions()

Gets an array of property definitions of contained properties.

string|null
getMainPropertyName()

Returns the name of the main property, if any.

Details

static DataDefinitionInterface createFromDataType(string $data_type)

Creates a new data definition object.

This method is typically used by \Drupal\Core\TypedData\TypedDataManager::createDataDefinition() to build a definition object for an arbitrary data type. When the definition class is known, it is recommended to directly use the static create() method on that class instead; e.g.:

Parameters

string $data_type

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

Return Value

DataDefinitionInterface

Exceptions

InvalidArgumentException

string getDataType()

Returns the data type of the data.

Return Value

string

The data type.

string|TranslatableMarkup getLabel()

Returns a human readable label.

Return Value

string|TranslatableMarkup

The label. A string or an instance of TranslatableMarkup will be returned based on the way the label translation is handled.

string|null getDescription()

Returns a human readable description.

Descriptions are usually used on user interfaces where the data is edited or displayed.

Return Value

string|null

The description, or NULL if no description is available.

bool isList()

Returns whether the data is multi-valued, i.e. a list of data items.

This is equivalent to checking whether the data definition implements the \Drupal\Core\TypedData\ListDefinitionInterface interface.

Return Value

bool

Whether the data is multi-valued.

bool isReadOnly()

Determines whether the data is read-only.

Return Value

bool

Whether the data is read-only.

bool isComputed()

Determines whether the data value is computed.

For example, data could be computed depending on some other values.

Return Value

bool

Whether the data value is computed.

bool isRequired()

Determines whether a data value is required.

For required data a non-NULL value is mandatory.

Return Value

bool

Whether a data value is required.

string getClass()

Returns the class used for creating the typed data object.

If not specified, the default class of the data type will be returned.

Return Value

string

The class used for creating the typed data object.

array getSettings()

Returns the array of settings, as required by the used class.

See the documentation of the class for supported or required settings.

Return Value

array

The array of settings.

mixed getSetting(string $setting_name)

Returns the value of a given setting.

Parameters

string $setting_name

The setting name.

Return Value

mixed

The setting value.

array[] getConstraints()

Returns an array of validation constraints.

The validation constraints of a definition consist of any for it defined constraints and default constraints, which are generated based on the definition and its data type. See \Drupal\Core\TypedData\TypedDataManager::getDefaultConstraints().

Constraints are defined via an array, having constraint plugin IDs as key and constraint options as values, e.g.

Return Value

array[]

An array of validation constraint definitions, keyed by constraint name. Each constraint definition can be used for instantiating \Symfony\Component\Validator\Constraint objects.

See also

ConstraintManager
Constraint

array getConstraint(string $constraint_name)

Returns a validation constraint.

See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details.

Parameters

string $constraint_name

The name of the constraint, i.e. its plugin id.

Return Value

array

A validation constraint definition which can be used for instantiating a \Symfony\Component\Validator\Constraint object.

See also

Constraint

DataDefinitionInterface addConstraint(string $constraint_name, array|null $options = NULL)

Adds a validation constraint.

See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details.

Parameters

string $constraint_name

The name of the constraint to add, i.e. its plugin id.

array|null $options

The constraint options as required by the constraint plugin, or NULL.

Return Value

DataDefinitionInterface

The object itself for chaining.

bool isInternal()

Determines whether the data value is internal.

This can be used in a scenario when it is not desirable to expose this data value to an external system.

The implications of this method are left to the discretion of the caller. For example, a module providing an HTTP API may not expose entities of this type, or a custom entity reference field settings form may deprioritize entities of this type in a select list.

Return Value

bool

Whether the data value is internal.

DataDefinitionInterface|null getPropertyDefinition(string $name)

Gets the definition of a contained property.

Parameters

string $name

The name of property.

Return Value

DataDefinitionInterface|null

The definition of the property or NULL if the property does not exist.

DataDefinitionInterface[] getPropertyDefinitions()

Gets an array of property definitions of contained properties.

Return Value

DataDefinitionInterface[]

An array of property definitions of contained properties, keyed by property name.

string|null getMainPropertyName()

Returns the name of the main property, if any.

Some field items consist mainly of one main property, e.g. the value of a text field or the @code target_id @endcode of an entity reference. If the field item has no main property, the method returns NULL.

Return Value

string|null

The name of the value property, or NULL if there is none.