FieldStorageDefinitionInterface.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. namespace Drupal\Core\Field;
  3. use Drupal\Core\Cache\CacheableDependencyInterface;
  4. use Drupal\Core\Entity\FieldableEntityInterface;
  5. /**
  6. * Defines an interface for entity field storage definitions.
  7. *
  8. * Field storage definitions represent the part of full field definitions (see
  9. * FieldDefinitionInterface) that is responsible for defining how the field is
  10. * stored. While field definitions may differ by entity bundle, all of those
  11. * bundle fields have to share the same common field storage definition. Thus,
  12. * the storage definitions can be defined by entity type only.
  13. * The bundle fields corresponding to a field storage definition may provide
  14. * additional information; e.g., they may provide bundle-specific settings or
  15. * constraints that are not present in the storage definition. However bundle
  16. * fields may not override or alter any information provided by the storage
  17. * definition except for the label and the description; e.g., any constraints
  18. * and settings on the storage definition must be present on the bundle field as
  19. * well.
  20. *
  21. * @see hook_entity_field_storage_info()
  22. */
  23. interface FieldStorageDefinitionInterface extends CacheableDependencyInterface {
  24. /**
  25. * Value indicating a field accepts an unlimited number of values.
  26. */
  27. const CARDINALITY_UNLIMITED = -1;
  28. /**
  29. * Returns the machine name of the field.
  30. *
  31. * This defines how the field data is accessed from the entity. For example,
  32. * if the field name is "foo", then $entity->foo returns its data.
  33. *
  34. * @return string
  35. * The field name.
  36. */
  37. public function getName();
  38. /**
  39. * Returns the field type.
  40. *
  41. * @return string
  42. * The field type, i.e. the id of a field type plugin. For example 'text'.
  43. *
  44. * @see \Drupal\Core\Field\FieldTypePluginManagerInterface
  45. */
  46. public function getType();
  47. /**
  48. * Returns the storage settings.
  49. *
  50. * Each field type defines the settings that are meaningful for that type.
  51. * For example, a text field can define a 'max_length' setting, and an image
  52. * field can define a 'alt_field_required' setting.
  53. *
  54. * The method always returns an array of all available settings for this field
  55. * type, possibly with the default values merged in if values have not been
  56. * provided for all available settings.
  57. *
  58. * @return mixed[]
  59. * An array of key/value pairs.
  60. */
  61. public function getSettings();
  62. /**
  63. * Returns the value of a given storage setting.
  64. *
  65. * @param string $setting_name
  66. * The setting name.
  67. *
  68. * @return mixed
  69. * The setting value.
  70. */
  71. public function getSetting($setting_name);
  72. /**
  73. * Returns whether the field supports translation.
  74. *
  75. * @return bool
  76. * TRUE if the field supports translation.
  77. */
  78. public function isTranslatable();
  79. /**
  80. * Sets whether the field supports translation.
  81. *
  82. * @param bool $translatable
  83. * Whether the field supports translation.
  84. *
  85. * @return $this
  86. */
  87. public function setTranslatable($translatable);
  88. /**
  89. * Returns whether the field storage is revisionable.
  90. *
  91. * Note that if the entity type is revisionable and the field storage has a
  92. * cardinality higher than 1, the field storage is considered revisionable
  93. * by default.
  94. *
  95. * @return bool
  96. * TRUE if the field is revisionable.
  97. */
  98. public function isRevisionable();
  99. /**
  100. * Determines whether the field is queryable via QueryInterface.
  101. *
  102. * @return bool
  103. * TRUE if the field is queryable.
  104. *
  105. * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use
  106. * \Drupal\Core\Field\FieldStorageDefinitionInterface::hasCustomStorage()
  107. * instead.
  108. *
  109. * @see https://www.drupal.org/node/2856563
  110. */
  111. public function isQueryable();
  112. /**
  113. * Returns the human-readable label for the field.
  114. *
  115. * @return string
  116. * The field label.
  117. */
  118. public function getLabel();
  119. /**
  120. * Returns the human-readable description for the field.
  121. *
  122. * This is displayed in addition to the label in places where additional
  123. * descriptive information is helpful. For example, as help text below the
  124. * form element in entity edit forms.
  125. *
  126. * @return string|null
  127. * The field description, or NULL if no description is available.
  128. */
  129. public function getDescription();
  130. /**
  131. * Gets an options provider for the given field item property.
  132. *
  133. * @param string $property_name
  134. * The name of the property to get options for; e.g., 'value'.
  135. * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
  136. * The entity for which the options should be provided.
  137. *
  138. * @return \Drupal\Core\TypedData\OptionsProviderInterface|null
  139. * An options provider, or NULL if no options are defined.
  140. */
  141. public function getOptionsProvider($property_name, FieldableEntityInterface $entity);
  142. /**
  143. * Returns whether the field can contain multiple items.
  144. *
  145. * @return bool
  146. * TRUE if the field can contain multiple items, FALSE otherwise.
  147. */
  148. public function isMultiple();
  149. /**
  150. * Returns the maximum number of items allowed for the field.
  151. *
  152. * Possible values are positive integers or
  153. * FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED.
  154. *
  155. * @return int
  156. * The field cardinality.
  157. */
  158. public function getCardinality();
  159. /**
  160. * Gets the definition of a contained property.
  161. *
  162. * @param string $name
  163. * The name of property.
  164. *
  165. * @return \Drupal\Core\TypedData\DataDefinitionInterface|null
  166. * The definition of the property or NULL if the property does not exist.
  167. */
  168. public function getPropertyDefinition($name);
  169. /**
  170. * Gets an array of property definitions of contained properties.
  171. *
  172. * @return \Drupal\Core\TypedData\DataDefinitionInterface[]
  173. * An array of property definitions of contained properties, keyed by
  174. * property name.
  175. */
  176. public function getPropertyDefinitions();
  177. /**
  178. * Returns the names of the field's subproperties.
  179. *
  180. * A field is a list of items, and each item can contain one or more
  181. * properties. All items for a given field contain the same property names,
  182. * but the values can be different for each item.
  183. *
  184. * For example, an email field might just contain a single 'value' property,
  185. * while a link field might contain 'title' and 'url' properties, and a text
  186. * field might contain 'value', 'summary', and 'format' properties.
  187. *
  188. * @return string[]
  189. * The property names.
  190. */
  191. public function getPropertyNames();
  192. /**
  193. * Returns the name of the main property, if any.
  194. *
  195. * Some field items consist mainly of one main property, e.g. the value of a
  196. * text field or the @code target_id @endcode of an entity reference. If the
  197. * field item has no main property, the method returns NULL.
  198. *
  199. * @return string|null
  200. * The name of the value property, or NULL if there is none.
  201. */
  202. public function getMainPropertyName();
  203. /**
  204. * Returns the ID of the entity type the field is attached to.
  205. *
  206. * This method should not be confused with EntityInterface::getEntityTypeId()
  207. * (configurable fields are config entities, and thus implement both
  208. * interfaces):
  209. * - FieldStorageDefinitionInterface::getTargetEntityTypeId() answers "as a
  210. * field storage, which entity type are you attached to?".
  211. * - EntityInterface::getEntityTypeId() answers "as a (config) entity, what
  212. * is your own entity type?".
  213. *
  214. * @return string
  215. * The entity type ID.
  216. */
  217. public function getTargetEntityTypeId();
  218. /**
  219. * Returns the field schema.
  220. *
  221. * Note that this method returns an empty array for computed fields which have
  222. * no schema.
  223. *
  224. * @return array[]
  225. * The field schema, as an array of key/value pairs in the format returned
  226. * by \Drupal\Core\Field\FieldItemInterface::schema():
  227. * - columns: An array of Schema API column specifications, keyed by column
  228. * name. This specifies what comprises a single value for a given field.
  229. * No assumptions should be made on how storage backends internally use
  230. * the original column name to structure their storage.
  231. * - indexes: An array of Schema API index definitions. Some storage
  232. * backends might not support indexes.
  233. * - unique keys: An array of Schema API unique key definitions. Some
  234. * storage backends might not support unique keys.
  235. * - foreign keys: An array of Schema API foreign key definitions. Note,
  236. * however, that depending on the storage backend specified for the field,
  237. * the field data is not necessarily stored in SQL.
  238. */
  239. public function getSchema();
  240. /**
  241. * Returns the field columns, as defined in the field schema.
  242. *
  243. * @return array[]
  244. * The array of field columns, keyed by column name, in the same format
  245. * returned by getSchema().
  246. *
  247. * @see \Drupal\Core\Field\FieldStorageDefinitionInterface::getSchema()
  248. */
  249. public function getColumns();
  250. /**
  251. * Returns an array of validation constraints.
  252. *
  253. * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
  254. * details.
  255. *
  256. * @return array[]
  257. * An array of validation constraint definitions, keyed by constraint name.
  258. * Each constraint definition can be used for instantiating
  259. * \Symfony\Component\Validator\Constraint objects.
  260. *
  261. * @see \Symfony\Component\Validator\Constraint
  262. */
  263. public function getConstraints();
  264. /**
  265. * Returns a validation constraint.
  266. *
  267. * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
  268. * details.
  269. *
  270. * @param string $constraint_name
  271. * The name of the constraint, i.e. its plugin id.
  272. *
  273. * @return array
  274. * A validation constraint definition which can be used for instantiating a
  275. * \Symfony\Component\Validator\Constraint object.
  276. *
  277. * @see \Symfony\Component\Validator\Constraint
  278. */
  279. public function getConstraint($constraint_name);
  280. /**
  281. * Returns the name of the provider of this field.
  282. *
  283. * @return string
  284. * The provider name; e.g., the module name.
  285. */
  286. public function getProvider();
  287. /**
  288. * Returns the storage behavior for this field.
  289. *
  290. * Indicates whether the entity type's storage should take care of storing the
  291. * field values or whether it is handled separately; e.g. by the
  292. * module providing the field.
  293. *
  294. * @return bool
  295. * FALSE if the storage takes care of storing the field, TRUE otherwise.
  296. */
  297. public function hasCustomStorage();
  298. /**
  299. * Determines whether the field is a base field.
  300. *
  301. * Base fields are not specific to a given bundle or a set of bundles. This
  302. * excludes configurable fields, as they are always attached to a specific
  303. * bundle.
  304. *
  305. * @return bool
  306. * Whether the field is a base field.
  307. */
  308. public function isBaseField();
  309. /**
  310. * Returns a unique identifier for the field storage.
  311. *
  312. * @return string
  313. */
  314. public function getUniqueStorageIdentifier();
  315. /**
  316. * Returns whether the field is deleted or not.
  317. *
  318. * @return bool
  319. * TRUE if the field is deleted, FALSE otherwise.
  320. */
  321. public function isDeleted();
  322. }