DataType.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Drupal\Core\TypedData\Annotation;
  3. use Drupal\Component\Annotation\Plugin;
  4. /**
  5. * Defines a data type annotation object.
  6. *
  7. * The typed data API allows modules to support any kind of data based upon
  8. * pre-defined primitive types and interfaces for complex data and lists.
  9. *
  10. * Defined data types may map to one of the pre-defined primitive types in
  11. * \Drupal\Core\TypedData\Primitive or may be complex data types, containing on
  12. * or more data properties. Typed data objects for complex data types have to
  13. * implement the \Drupal\Core\TypedData\ComplexDataInterface. Further interface
  14. * that may be implemented are:
  15. * - \Drupal\Core\Access\AccessibleInterface
  16. * - \Drupal\Core\TypedData\TranslatableInterface
  17. *
  18. * Furthermore, lists of data items are represented by objects implementing the
  19. * \Drupal\Core\TypedData\ListInterface. A list contains items of the same data
  20. * type, is ordered and may contain duplicates. The class used for a list of
  21. * items of a certain type may be specified using the 'list class' key.
  22. *
  23. * @see \Drupal::typedDataManager()
  24. * @see \Drupal\Core\TypedData\TypedDataManager::create()
  25. * @see hook_data_type_info_alter()
  26. *
  27. * @ingroup typed_data
  28. *
  29. * @Annotation
  30. */
  31. class DataType extends Plugin {
  32. /**
  33. * The data type plugin ID.
  34. *
  35. * @var string
  36. */
  37. public $id;
  38. /**
  39. * The human-readable name of the data type.
  40. *
  41. * @ingroup plugin_translatable
  42. *
  43. * @var \Drupal\Core\Annotation\Translation
  44. */
  45. public $label;
  46. /**
  47. * The description of the data type.
  48. *
  49. * @ingroup plugin_translatable
  50. *
  51. * @var \Drupal\Core\Annotation\Translation
  52. */
  53. public $description;
  54. /**
  55. * The definition class to use for defining data of this type.
  56. * Must implement the \Drupal\Core\TypedData\DataDefinitionInterface.
  57. *
  58. * @var string
  59. */
  60. public $definition_class = '\Drupal\Core\TypedData\DataDefinition';
  61. /**
  62. * The typed data class used for wrapping multiple data items of the type.
  63. * Must implement the \Drupal\Core\TypedData\ListInterface.
  64. *
  65. * @var string
  66. */
  67. public $list_class = '\Drupal\Core\TypedData\Plugin\DataType\ItemList';
  68. /**
  69. * The definition class to use for defining a list of items of this type.
  70. * Must implement the \Drupal\Core\TypedData\ListDataDefinitionInterface.
  71. *
  72. * @var string
  73. */
  74. public $list_definition_class = '\Drupal\Core\TypedData\ListDataDefinition';
  75. /**
  76. * The pre-defined primitive type that this data type maps to.
  77. *
  78. * If set, it must be a constant defined by \Drupal\Core\TypedData\Primitive
  79. * such as \Drupal\Core\TypedData\Primitive::STRING.
  80. *
  81. * @var string
  82. */
  83. public $primitive_type;
  84. /**
  85. * An array of validation constraints for this type.
  86. *
  87. * @var array
  88. *
  89. * @see \Drupal\Core\TypedData\TypedDataManager::getConstraints().
  90. */
  91. public $constraints;
  92. /**
  93. * Whether the typed object wraps the canonical representation of the data.
  94. *
  95. * @var bool
  96. *
  97. * @see \Drupal\Core\TypedData\TypedDataManager::getCanonicalRepresentation()
  98. */
  99. public $unwrap_for_canonical_representation = TRUE;
  100. }