3 namespace Drupal\Core\TypedData\Annotation;
5 use Drupal\Component\Annotation\Plugin;
8 * Defines a data type annotation object.
10 * The typed data API allows modules to support any kind of data based upon
11 * pre-defined primitive types and interfaces for complex data and lists.
13 * Defined data types may map to one of the pre-defined primitive types in
14 * \Drupal\Core\TypedData\Primitive or may be complex data types, containing on
15 * or more data properties. Typed data objects for complex data types have to
16 * implement the \Drupal\Core\TypedData\ComplexDataInterface. Further interface
17 * that may be implemented are:
18 * - \Drupal\Core\Access\AccessibleInterface
19 * - \Drupal\Core\TypedData\TranslatableInterface
21 * Furthermore, lists of data items are represented by objects implementing the
22 * \Drupal\Core\TypedData\ListInterface. A list contains items of the same data
23 * type, is ordered and may contain duplicates. The class used for a list of
24 * items of a certain type may be specified using the 'list class' key.
26 * @see \Drupal::typedDataManager()
27 * @see \Drupal\Core\TypedData\TypedDataManager::create()
28 * @see hook_data_type_info_alter()
34 class DataType extends Plugin {
37 * The data type plugin ID.
44 * The human-readable name of the data type.
46 * @ingroup plugin_translatable
48 * @var \Drupal\Core\Annotation\Translation
53 * The description of the data type.
55 * @ingroup plugin_translatable
57 * @var \Drupal\Core\Annotation\Translation
62 * The definition class to use for defining data of this type.
63 * Must implement the \Drupal\Core\TypedData\DataDefinitionInterface.
67 public $definition_class = '\Drupal\Core\TypedData\DataDefinition';
70 * The typed data class used for wrapping multiple data items of the type.
71 * Must implement the \Drupal\Core\TypedData\ListInterface.
75 public $list_class = '\Drupal\Core\TypedData\Plugin\DataType\ItemList';
78 * The definition class to use for defining a list of items of this type.
79 * Must implement the \Drupal\Core\TypedData\ListDataDefinitionInterface.
83 public $list_definition_class = '\Drupal\Core\TypedData\ListDataDefinition';
86 * The pre-defined primitive type that this data type maps to.
88 * If set, it must be a constant defined by \Drupal\Core\TypedData\Primitive
89 * such as \Drupal\Core\TypedData\Primitive::STRING.
93 public $primitive_type;
96 * An array of validation constraints for this type.
100 * @see \Drupal\Core\TypedData\TypedDataManager::getConstraints().
105 * Whether the typed object wraps the canonical representation of the data.
109 * @see \Drupal\Core\TypedData\TypedDataManager::getCanonicalRepresentation()
111 public $unwrap_for_canonical_representation = TRUE;