FieldStorageDefinitionInterface.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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 is revisionable.
  90. *
  91. * @return bool
  92. * TRUE if the field is revisionable.
  93. */
  94. public function isRevisionable();
  95. /**
  96. * Determines whether the field is queryable via QueryInterface.
  97. *
  98. * @return bool
  99. * TRUE if the field is queryable.
  100. *
  101. * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use
  102. * \Drupal\Core\Field\FieldStorageDefinitionInterface::hasCustomStorage()
  103. * instead.
  104. *
  105. * @see https://www.drupal.org/node/2856563
  106. */
  107. public function isQueryable();
  108. /**
  109. * Returns the human-readable label for the field.
  110. *
  111. * @return string
  112. * The field label.
  113. */
  114. public function getLabel();
  115. /**
  116. * Returns the human-readable description for the field.
  117. *
  118. * This is displayed in addition to the label in places where additional
  119. * descriptive information is helpful. For example, as help text below the
  120. * form element in entity edit forms.
  121. *
  122. * @return string|null
  123. * The field description, or NULL if no description is available.
  124. */
  125. public function getDescription();
  126. /**
  127. * Gets an options provider for the given field item property.
  128. *
  129. * @param string $property_name
  130. * The name of the property to get options for; e.g., 'value'.
  131. * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
  132. * The entity for which the options should be provided.
  133. *
  134. * @return \Drupal\Core\TypedData\OptionsProviderInterface|null
  135. * An options provider, or NULL if no options are defined.
  136. */
  137. public function getOptionsProvider($property_name, FieldableEntityInterface $entity);
  138. /**
  139. * Returns whether the field can contain multiple items.
  140. *
  141. * @return bool
  142. * TRUE if the field can contain multiple items, FALSE otherwise.
  143. */
  144. public function isMultiple();
  145. /**
  146. * Returns the maximum number of items allowed for the field.
  147. *
  148. * Possible values are positive integers or
  149. * FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED.
  150. *
  151. * @return int
  152. * The field cardinality.
  153. */
  154. public function getCardinality();
  155. /**
  156. * Gets the definition of a contained property.
  157. *
  158. * @param string $name
  159. * The name of property.
  160. *
  161. * @return \Drupal\Core\TypedData\DataDefinitionInterface|null
  162. * The definition of the property or NULL if the property does not exist.
  163. */
  164. public function getPropertyDefinition($name);
  165. /**
  166. * Gets an array of property definitions of contained properties.
  167. *
  168. * @return \Drupal\Core\TypedData\DataDefinitionInterface[]
  169. * An array of property definitions of contained properties, keyed by
  170. * property name.
  171. */
  172. public function getPropertyDefinitions();
  173. /**
  174. * Returns the names of the field's subproperties.
  175. *
  176. * A field is a list of items, and each item can contain one or more
  177. * properties. All items for a given field contain the same property names,
  178. * but the values can be different for each item.
  179. *
  180. * For example, an email field might just contain a single 'value' property,
  181. * while a link field might contain 'title' and 'url' properties, and a text
  182. * field might contain 'value', 'summary', and 'format' properties.
  183. *
  184. * @return string[]
  185. * The property names.
  186. */
  187. public function getPropertyNames();
  188. /**
  189. * Returns the name of the main property, if any.
  190. *
  191. * Some field items consist mainly of one main property, e.g. the value of a
  192. * text field or the @code target_id @endcode of an entity reference. If the
  193. * field item has no main property, the method returns NULL.
  194. *
  195. * @return string|null
  196. * The name of the value property, or NULL if there is none.
  197. */
  198. public function getMainPropertyName();
  199. /**
  200. * Returns the ID of the entity type the field is attached to.
  201. *
  202. * This method should not be confused with EntityInterface::getEntityTypeId()
  203. * (configurable fields are config entities, and thus implement both
  204. * interfaces):
  205. * - FieldStorageDefinitionInterface::getTargetEntityTypeId() answers "as a
  206. * field storage, which entity type are you attached to?".
  207. * - EntityInterface::getEntityTypeId() answers "as a (config) entity, what
  208. * is your own entity type?".
  209. *
  210. * @return string
  211. * The entity type ID.
  212. */
  213. public function getTargetEntityTypeId();
  214. /**
  215. * Returns the field schema.
  216. *
  217. * Note that this method returns an empty array for computed fields which have
  218. * no schema.
  219. *
  220. * @return array[]
  221. * The field schema, as an array of key/value pairs in the format returned
  222. * by \Drupal\Core\Field\FieldItemInterface::schema():
  223. * - columns: An array of Schema API column specifications, keyed by column
  224. * name. This specifies what comprises a single value for a given field.
  225. * No assumptions should be made on how storage backends internally use
  226. * the original column name to structure their storage.
  227. * - indexes: An array of Schema API index definitions. Some storage
  228. * backends might not support indexes.
  229. * - unique keys: An array of Schema API unique key definitions. Some
  230. * storage backends might not support unique keys.
  231. * - foreign keys: An array of Schema API foreign key definitions. Note,
  232. * however, that depending on the storage backend specified for the field,
  233. * the field data is not necessarily stored in SQL.
  234. */
  235. public function getSchema();
  236. /**
  237. * Returns the field columns, as defined in the field schema.
  238. *
  239. * @return array[]
  240. * The array of field columns, keyed by column name, in the same format
  241. * returned by getSchema().
  242. *
  243. * @see \Drupal\Core\Field\FieldStorageDefinitionInterface::getSchema()
  244. */
  245. public function getColumns();
  246. /**
  247. * Returns an array of validation constraints.
  248. *
  249. * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
  250. * details.
  251. *
  252. * @return array[]
  253. * An array of validation constraint definitions, keyed by constraint name.
  254. * Each constraint definition can be used for instantiating
  255. * \Symfony\Component\Validator\Constraint objects.
  256. *
  257. * @see \Symfony\Component\Validator\Constraint
  258. */
  259. public function getConstraints();
  260. /**
  261. * Returns a validation constraint.
  262. *
  263. * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
  264. * details.
  265. *
  266. * @param string $constraint_name
  267. * The name of the constraint, i.e. its plugin id.
  268. *
  269. * @return array
  270. * A validation constraint definition which can be used for instantiating a
  271. * \Symfony\Component\Validator\Constraint object.
  272. *
  273. * @see \Symfony\Component\Validator\Constraint
  274. */
  275. public function getConstraint($constraint_name);
  276. /**
  277. * Returns the name of the provider of this field.
  278. *
  279. * @return string
  280. * The provider name; e.g., the module name.
  281. */
  282. public function getProvider();
  283. /**
  284. * Returns the storage behavior for this field.
  285. *
  286. * Indicates whether the entity type's storage should take care of storing the
  287. * field values or whether it is handled separately; e.g. by the
  288. * module providing the field.
  289. *
  290. * @return bool
  291. * FALSE if the storage takes care of storing the field, TRUE otherwise.
  292. */
  293. public function hasCustomStorage();
  294. /**
  295. * Determines whether the field is a base field.
  296. *
  297. * Base fields are not specific to a given bundle or a set of bundles. This
  298. * excludes configurable fields, as they are always attached to a specific
  299. * bundle.
  300. *
  301. * @return bool
  302. * Whether the field is a base field.
  303. */
  304. public function isBaseField();
  305. /**
  306. * Returns a unique identifier for the field storage.
  307. *
  308. * @return string
  309. */
  310. public function getUniqueStorageIdentifier();
  311. /**
  312. * Returns whether the field is deleted or not.
  313. *
  314. * @return bool
  315. * TRUE if the field is deleted, FALSE otherwise.
  316. */
  317. public function isDeleted();
  318. }