DataDefinitionInterface
interface DataDefinitionInterface (View source)
Interface for data definitions.
Data definitions are used to describe data based upon available data types. For example, a plugin could describe its parameters using data definitions in order to specify what kind of data is required for it.
Definitions that describe lists or complex data have to implement the respective interfaces, such that the metadata about contained list items or properties can be retrieved from the definition.
Methods
Creates a new data definition object.
Returns the data type of the data.
Returns a human readable label.
Returns a human readable description.
Returns whether the data is multi-valued, i.e. a list of data items.
Determines whether the data is read-only.
Determines whether the data value is computed.
Determines whether a data value is required.
Returns the class used for creating the typed data object.
Returns the array of settings, as required by the used class.
Returns the value of a given setting.
Returns an array of validation constraints.
Returns a validation constraint.
Adds a validation constraint.
Determines whether the data value is internal.
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.:
string
getDataType()
Returns the data type of the data.
string|TranslatableMarkup
getLabel()
Returns a human readable label.
string|null
getDescription()
Returns a human readable description.
Descriptions are usually used on user interfaces where the data is edited or displayed.
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.
bool
isReadOnly()
Determines 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.
bool
isRequired()
Determines whether a data value is required.
For required data a non-NULL value is mandatory.
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.
array
getSettings()
Returns the array of settings, as required by the used class.
See the documentation of the class for supported or required settings.
mixed
getSetting(string $setting_name)
Returns the value of a given setting.
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.
array
getConstraint(string $constraint_name)
Returns a validation constraint.
See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details.
DataDefinitionInterface
addConstraint(string $constraint_name, array|null $options = NULL)
Adds a validation constraint.
See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details.
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.