Typed Data API

API for describing data based on a set of available data types.

The Typed Data API was created to provide developers with a consistent interface for interacting with data, as well as an API for metadata (information about the data, such as the data type, whether it is translatable, and who can access it). The Typed Data API is used in several Drupal sub-systems, such as the Entity Field API and Configuration API.

See https://drupal.org/node/1794140 for more information about the Typed Data API.

Interfaces and classes in the Typed Data API

There are several basic interfaces in the Typed Data API, representing different types of data:

Defining data types

To define a new data type:

  • Create a class that implements one of the Typed Data interfaces. Typically, you will want to extend one of the classes listed in the section above as a starting point.
  • Make your class into a DataType plugin. To do that, put it in namespace \Drupal\yourmodule\Plugin\DataType (where "yourmodule" is your module's short name), and add annotation of type \Drupal\Core\TypedData\Annotation\DataType to the documentation header. See the Plugin API topic and the Annotations topic for more information.

Using data types

The data types of the Typed Data API can be used in several ways, once they have been defined:

  • In the Field API, data types can be used as the class in the property definition of the field. See the Field API topic for more information.
  • In configuration schema files, you can use the unique ID ('id' annotation) from any DataType plugin class as the 'type' value for an entry. See the Confuration API topic for more information.

Classes

Namesort descending Location Description
DataType drupal/core/lib/Drupal/Core/TypedData/Annotation/DataType.php Defines a data type annotation object.
ItemList drupal/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php A generic list class.
Map drupal/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php The "map" data type.
TypedData drupal/core/lib/Drupal/Core/TypedData/TypedData.php The abstract base class for typed data.

Interfaces

Namesort descending Location Description
BinaryInterface drupal/core/lib/Drupal/Core/TypedData/Type/BinaryInterface.php Interface for binary data.
ComplexDataDefinitionInterface drupal/core/lib/Drupal/Core/TypedData/ComplexDataDefinitionInterface.php Interface for complex data definitions.
ComplexDataInterface drupal/core/lib/Drupal/Core/TypedData/ComplexDataInterface.php Interface for complex data; i.e. data containing named and typed properties.
DataDefinitionInterface drupal/core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php Interface for data definitions.
DataReferenceDefinitionInterface drupal/core/lib/Drupal/Core/TypedData/DataReferenceDefinitionInterface.php Interface for typed data references.
DateTimeInterface drupal/core/lib/Drupal/Core/TypedData/Type/DateTimeInterface.php Interface for dates, optionally including a time.
DurationInterface drupal/core/lib/Drupal/Core/TypedData/Type/DurationInterface.php Interface for durations.
FloatInterface drupal/core/lib/Drupal/Core/TypedData/Type/FloatInterface.php Interface for floating-point numbers.
IntegerInterface drupal/core/lib/Drupal/Core/TypedData/Type/IntegerInterface.php Interface for integer numbers.
ListDataDefinitionInterface drupal/core/lib/Drupal/Core/TypedData/ListDataDefinitionInterface.php Interface for data definitions of lists.
ListInterface drupal/core/lib/Drupal/Core/TypedData/ListInterface.php Interface for a list of typed data.
PrimitiveInterface drupal/core/lib/Drupal/Core/TypedData/PrimitiveInterface.php Interface for primitive data.
StringInterface drupal/core/lib/Drupal/Core/TypedData/Type/StringInterface.php Interface for strings.
TypedDataInterface drupal/core/lib/Drupal/Core/TypedData/TypedDataInterface.php Interface for typed data objects.
UriInterface drupal/core/lib/Drupal/Core/TypedData/Type/UriInterface.php Interface for URIs.

File

drupal/core/modules/system/core.api.php, line 1048
Documentation landing page and topics, plus core library hooks.