EntityTypeInterface.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. <?php
  2. namespace Drupal\Core\Entity;
  3. use Drupal\Component\Plugin\Definition\PluginDefinitionInterface;
  4. /**
  5. * Provides an interface for an entity type and its metadata.
  6. *
  7. * Additional information can be provided by modules: hook_entity_type_build() can be
  8. * implemented to define new properties, while hook_entity_type_alter() can be
  9. * implemented to alter existing data and fill-in defaults. Module-specific
  10. * properties should be documented in the hook implementations defining them.
  11. */
  12. interface EntityTypeInterface extends PluginDefinitionInterface {
  13. /**
  14. * The maximum length of ID, in characters.
  15. */
  16. const ID_MAX_LENGTH = 32;
  17. /**
  18. * The maximum length of bundle name, in characters.
  19. */
  20. const BUNDLE_MAX_LENGTH = 32;
  21. /**
  22. * Gets any arbitrary property.
  23. *
  24. * @param string $property
  25. * The property to retrieve.
  26. *
  27. * @return mixed
  28. * The value for that property, or NULL if the property does not exist.
  29. */
  30. public function get($property);
  31. /**
  32. * Sets a value to an arbitrary property.
  33. *
  34. * @param string $property
  35. * The property to use for the value.
  36. * @param mixed $value
  37. * The value to set.
  38. *
  39. * @return $this
  40. */
  41. public function set($property, $value);
  42. /**
  43. * Gets the name of the original entity type class.
  44. *
  45. * In case the class name was changed with setClass(), this will return
  46. * the initial value. Useful when trying to identify the entity type ID based
  47. * on the class.
  48. *
  49. * @return string
  50. * The name of the original entity type class.
  51. */
  52. public function getOriginalClass();
  53. /**
  54. * Gets an array of entity keys.
  55. *
  56. * @return array
  57. * An array describing how the Field API can extract certain information
  58. * from objects of this entity type:
  59. * - id: The name of the property that contains the primary ID of the
  60. * entity. Every entity object passed to the Field API must have this
  61. * property and its value must be numeric.
  62. * - revision: (optional) The name of the property that contains the
  63. * revision ID of the entity. The Field API assumes that all revision IDs
  64. * are unique across all entities of a type. If this entry is omitted
  65. * the entities of this type are not revisionable.
  66. * - bundle: (optional) The name of the property that contains the bundle
  67. * name for the entity. The bundle name defines which set of fields are
  68. * attached to the entity (e.g. what nodes call "content type"). This
  69. * entry can be omitted if this entity type exposes a single bundle (such
  70. * that all entities have the same collection of fields). The name of this
  71. * single bundle will be the same as the entity type.
  72. * - label: (optional) The name of the property that contains the entity
  73. * label. For example, if the entity's label is located in
  74. * $entity->subject, then 'subject' should be specified here. If complex
  75. * logic is required to build the label,
  76. * \Drupal\Core\Entity\EntityInterface::label() should be used.
  77. * - langcode: (optional) The name of the property that contains the
  78. * language code. For instance, if the entity's language is located in
  79. * $entity->langcode, then 'langcode' should be specified here.
  80. * - uuid: (optional) The name of the property that contains the universally
  81. * unique identifier of the entity, which is used to distinctly identify
  82. * an entity across different systems.
  83. */
  84. public function getKeys();
  85. /**
  86. * Gets a specific entity key.
  87. *
  88. * @param string $key
  89. * The name of the entity key to return.
  90. *
  91. * @return string|bool
  92. * The entity key, or FALSE if it does not exist.
  93. *
  94. * @see self::getKeys()
  95. */
  96. public function getKey($key);
  97. /**
  98. * Indicates if a given entity key exists.
  99. *
  100. * @param string $key
  101. * The name of the entity key to check.
  102. *
  103. * @return bool
  104. * TRUE if a given entity key exists, FALSE otherwise.
  105. */
  106. public function hasKey($key);
  107. /**
  108. * Indicates whether entities should be statically cached.
  109. *
  110. * @return bool
  111. * TRUE if static caching should be used; FALSE otherwise.
  112. */
  113. public function isStaticallyCacheable();
  114. /**
  115. * Indicates whether the rendered output of entities should be cached.
  116. *
  117. * @return bool
  118. */
  119. public function isRenderCacheable();
  120. /**
  121. * Indicates if the persistent cache of field data should be used.
  122. *
  123. * @todo Used by ContentEntityStorageBase only.
  124. *
  125. * The persistent cache should usually only be disabled if a higher level
  126. * persistent cache is available for the entity type.
  127. *
  128. * @return bool
  129. */
  130. public function isPersistentlyCacheable();
  131. /**
  132. * Determines if there is a handler for a given type.
  133. *
  134. * @param string $handler_type
  135. * The type of handler to check.
  136. * @param bool $nested
  137. * (optional) If this handler has a nested definition. Defaults to FALSE.
  138. *
  139. * @return bool
  140. * TRUE if a handler of this type exists, FALSE otherwise.
  141. */
  142. public function hasHandlerClass($handler_type, $nested = FALSE);
  143. /**
  144. * @param string $handler_type
  145. * The handler type to get.
  146. *
  147. * @return array|string|null
  148. * The handlers for a given type, or NULL if none exist.
  149. */
  150. public function getHandlerClass($handler_type);
  151. /**
  152. * Gets an array of handlers.
  153. *
  154. * @return array
  155. * An associative array where the keys are the names of different handler
  156. * types (listed below) and the values are the names of the classes that
  157. * implement that handler:
  158. * - storage: The name of the class used to load the objects. The class must
  159. * implement \Drupal\Core\Entity\EntityStorageInterface.
  160. * - form: An associative array where the keys are the names of the
  161. * different form operations (such as 'create', 'edit', or 'delete') and
  162. * the values are the names of the handler classes for those
  163. * operations. The name of the operation is passed also to the form
  164. * handler's constructor, so that one class can be used for multiple
  165. * entity forms when the forms are similar. The classes must implement
  166. * \Drupal\Core\Entity\EntityFormInterface.
  167. * - list: The name of the class that provides listings of the entities. The
  168. * class must implement \Drupal\Core\Entity\EntityListBuilderInterface.
  169. * - render: The name of the class that is used to render the entities. The
  170. * class must implement \Drupal\Core\Entity\EntityViewBuilderInterface.
  171. * - access: The name of the class that is used for access checks. The class
  172. * must implement \Drupal\Core\Entity\EntityAccessControlHandlerInterface.
  173. * Defaults to \Drupal\Core\Entity\EntityAccessControlHandler.
  174. * - route_provider: (optional) A list of class names, keyed by a group
  175. * string, which will be used to define routes related to this entity
  176. * type. These classes must implement
  177. * \Drupal\Core\Entity\Routing\EntityRouteProviderInterface.
  178. */
  179. public function getHandlerClasses();
  180. /**
  181. * Gets the storage class.
  182. *
  183. * @return string
  184. * The class for this entity type's storage.
  185. */
  186. public function getStorageClass();
  187. /**
  188. * Sets the storage class.
  189. *
  190. * @param string $class
  191. * The class for this entity type's storage.
  192. *
  193. * @return $this
  194. */
  195. public function setStorageClass($class);
  196. /**
  197. * Gets the form class for a specific operation.
  198. *
  199. * @param string $operation
  200. * The name of the operation to use, e.g., 'default'.
  201. *
  202. * @return string
  203. * The class for this operation's form for this entity type.
  204. *
  205. * @see \Drupal\Core\Entity\EntityFormBuilderInterface
  206. */
  207. public function getFormClass($operation);
  208. /**
  209. * Sets a form class for a specific operation.
  210. *
  211. * @param string $operation
  212. * The operation to use this form class for.
  213. * @param string $class
  214. * The form class implementing
  215. * \Drupal\Core\Entity\EntityFormInterface.
  216. *
  217. * @return $this
  218. *
  219. * @see \Drupal\Core\Entity\EntityFormBuilderInterface
  220. */
  221. public function setFormClass($operation, $class);
  222. /**
  223. * Indicates if this entity type has any forms.
  224. *
  225. * @return bool
  226. * TRUE if there are any forms for this entity type, FALSE otherwise.
  227. */
  228. public function hasFormClasses();
  229. /**
  230. * Indicates if this entity type has any route provider.
  231. *
  232. * @return bool
  233. */
  234. public function hasRouteProviders();
  235. /**
  236. * Gets all the route provide handlers.
  237. *
  238. * Much like forms you can define multiple route provider handlers.
  239. *
  240. * @return string[]
  241. */
  242. public function getRouteProviderClasses();
  243. /**
  244. * Gets the list class.
  245. *
  246. * @return string
  247. * The class for this entity type's list.
  248. */
  249. public function getListBuilderClass();
  250. /**
  251. * Sets the list class.
  252. *
  253. * @param string $class
  254. * The list class to use for the operation.
  255. *
  256. * @return $this
  257. */
  258. public function setListBuilderClass($class);
  259. /**
  260. * Indicates if this entity type has a list class.
  261. *
  262. * @return bool
  263. * TRUE if there is a list for this entity type, FALSE otherwise.
  264. */
  265. public function hasListBuilderClass();
  266. /**
  267. * Gets the view builder class.
  268. *
  269. * @return string
  270. * The class for this entity type's view builder.
  271. */
  272. public function getViewBuilderClass();
  273. /**
  274. * Gets the view builder class.
  275. *
  276. * @param string $class
  277. * The class for this entity type's view builder.
  278. *
  279. * @return $this
  280. */
  281. public function setViewBuilderClass($class);
  282. /**
  283. * Indicates if this entity type has a view builder.
  284. *
  285. * @return bool
  286. * TRUE if there is a view builder for this entity type, FALSE otherwise.
  287. */
  288. public function hasViewBuilderClass();
  289. /**
  290. * Gets the access control class.
  291. *
  292. * @return string
  293. * The class for this entity type's access control.
  294. */
  295. public function getAccessControlClass();
  296. /**
  297. * Gets the access class.
  298. *
  299. * @param string $class
  300. * The class for this entity type's access.
  301. *
  302. * @return $this
  303. */
  304. public function setAccessClass($class);
  305. /**
  306. * Indicates if the entity type class implements the given interface.
  307. *
  308. * @param string $interface
  309. * The class or interface to check.
  310. *
  311. * @return bool
  312. * TRUE if the entity type class implements the given interface.
  313. */
  314. public function entityClassImplements($interface);
  315. /**
  316. * Indicates if the entity type is a subclass of the given class or interface.
  317. *
  318. * @param string $class
  319. * The class or interface to check.
  320. *
  321. * @return bool
  322. * TRUE if the entity type is a subclass of the class or interface.
  323. *
  324. * @deprecated in Drupal 8.3.0 and will be removed before Drupal 9.0.0.
  325. * Use Drupal\Core\Entity\EntityTypeInterface::entityClassImplements()
  326. * instead.
  327. */
  328. public function isSubclassOf($class);
  329. /**
  330. * Sets the handlers for a given type.
  331. *
  332. * @param string $handler_type
  333. * The type of handler to set.
  334. * @param array|string $value
  335. * The value for a handler type.
  336. *
  337. * @return $this
  338. */
  339. public function setHandlerClass($handler_type, $value);
  340. /**
  341. * Gets the name of the default administrative permission.
  342. *
  343. * The default \Drupal\Core\Entity\EntityAccessControlHandler class checks this
  344. * permission for all operations in its checkAccess() method. Entities with
  345. * more complex permissions can extend this class to do their own access
  346. * checks.
  347. *
  348. * @return string|bool
  349. */
  350. public function getAdminPermission();
  351. /**
  352. * Gets the permission granularity level.
  353. *
  354. * The allowed values are respectively "entity_type" or "bundle".
  355. *
  356. * @return string
  357. * Whether a module exposing permissions for the current entity type
  358. * should use entity-type level granularity or bundle level granularity.
  359. */
  360. public function getPermissionGranularity();
  361. /**
  362. * Gets the link templates using the URI template syntax.
  363. *
  364. * Links are an array of standard link relations to the URI template that
  365. * should be used for them. Where possible, link relationships should use
  366. * established IANA relationships rather than custom relationships.
  367. *
  368. * Every entity type should, at minimum, define "canonical", which is the
  369. * pattern for URIs to that entity. Even if the entity will have no HTML page
  370. * exposed to users it should still have a canonical URI in order to be
  371. * compatible with web services. Entities that will be user-editable via an
  372. * HTML page must also define an "edit-form" relationship.
  373. *
  374. * By default, the following placeholders are supported:
  375. * - [entityType]: The entity type itself will also be a valid token for the
  376. * ID of the entity. For instance, a placeholder of {node} used on the Node
  377. * class.
  378. * - [bundleEntityType]: The bundle machine name itself. For instance, a
  379. * placeholder of {node_type} used on the Node class.
  380. *
  381. * Specific entity types may also expand upon this list by overriding the
  382. * Entity::urlRouteParameters() method.
  383. *
  384. * @link http://www.iana.org/assignments/link-relations/link-relations.xml @endlink
  385. * @link http://tools.ietf.org/html/rfc6570 @endlink
  386. *
  387. * @return array
  388. */
  389. public function getLinkTemplates();
  390. /**
  391. * Gets the link template for a given key.
  392. *
  393. * @param string $key
  394. * The link type.
  395. *
  396. * @return string|bool
  397. * The path for this link, or FALSE if it doesn't exist.
  398. */
  399. public function getLinkTemplate($key);
  400. /**
  401. * Indicates if a link template exists for a given key.
  402. *
  403. * @param string $key
  404. * The link type.
  405. *
  406. * @return bool
  407. * TRUE if the link template exists, FALSE otherwise.
  408. */
  409. public function hasLinkTemplate($key);
  410. /**
  411. * Sets a single link template.
  412. *
  413. * @param string $key
  414. * The name of a link.
  415. * @param string $path
  416. * The route path to use for the link.
  417. *
  418. * @return $this
  419. *
  420. * @throws \InvalidArgumentException
  421. * Thrown when the path does not start with a leading slash.
  422. */
  423. public function setLinkTemplate($key, $path);
  424. /**
  425. * Gets the callback for the label of the entity.
  426. *
  427. * The function takes an entity and returns the label of the entity. Use
  428. * language() on the entity to get information on the requested language. The
  429. * entity label is the main string associated with an entity; for example, the
  430. * title of a node or the subject of a comment. If there is an entity object
  431. * property that defines the label, use the 'label' element of the
  432. * 'entity_keys' return value component to provide this information. If more
  433. * complex logic is needed to determine the label of an entity, you can
  434. * instead specify a callback function here, which will be called to determine
  435. * the entity label.
  436. *
  437. * @return callable|null
  438. * The callback, or NULL if none exists.
  439. *
  440. * @deprecated in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0.
  441. * Use Drupal\Core\Entity\EntityInterface::label() for complex label
  442. * generation as needed.
  443. *
  444. * @see \Drupal\Core\Entity\EntityInterface::label()
  445. * @see \Drupal\Core\Entity\EntityTypeInterface::setLabelCallback()
  446. * @see \Drupal\Core\Entity\EntityTypeInterface::hasLabelCallback()
  447. *
  448. * @todo Remove usages of label_callback https://www.drupal.org/node/2450793.
  449. */
  450. public function getLabelCallback();
  451. /**
  452. * Sets the label callback.
  453. *
  454. * @param callable $callback
  455. * A callable that returns the label of the entity.
  456. *
  457. * @return $this
  458. *
  459. * @deprecated in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0.
  460. * Use EntityInterface::label() for complex label generation as needed.
  461. *
  462. * @see \Drupal\Core\Entity\EntityInterface::label()
  463. * @see \Drupal\Core\Entity\EntityTypeInterface::getLabelCallback()
  464. * @see \Drupal\Core\Entity\EntityTypeInterface::hasLabelCallback()
  465. */
  466. public function setLabelCallback($callback);
  467. /**
  468. * Indicates if a label callback exists.
  469. *
  470. * @return bool
  471. *
  472. * @deprecated in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0.
  473. * Use EntityInterface::label() for complex label generation as needed.
  474. *
  475. * @see \Drupal\Core\Entity\EntityInterface::label()
  476. * @see \Drupal\Core\Entity\EntityTypeInterface::getLabelCallback()
  477. * @see \Drupal\Core\Entity\EntityTypeInterface::setLabelCallback()
  478. */
  479. public function hasLabelCallback();
  480. /**
  481. * Gets the name of the entity type which provides bundles.
  482. *
  483. * @return string|null
  484. * The name of the entity type which provides bundles, or NULL if the entity
  485. * type does not have a bundle entity type.
  486. */
  487. public function getBundleEntityType();
  488. /**
  489. * Gets the entity type for which this entity provides bundles.
  490. *
  491. * It can be used by other modules to act accordingly; for example,
  492. * the Field UI module uses it to add operation links to manage fields and
  493. * displays.
  494. *
  495. * @return string|null
  496. * The entity type for which this entity provides bundles, or NULL if does
  497. * not provide bundles for another entity type.
  498. */
  499. public function getBundleOf();
  500. /**
  501. * Gets the label for the bundle.
  502. *
  503. * @return string
  504. * The bundle label.
  505. */
  506. public function getBundleLabel();
  507. /**
  508. * Gets the name of the entity's base table.
  509. *
  510. * @todo Used by SqlContentEntityStorage only.
  511. *
  512. * @return string|null
  513. * The name of the entity's base table, or NULL if none exists.
  514. */
  515. public function getBaseTable();
  516. /**
  517. * Indicates whether the entity data is internal.
  518. *
  519. * This can be used in a scenario when it is not desirable to expose data of
  520. * this entity type to an external system.
  521. *
  522. * The implications of this method are left to the discretion of the caller.
  523. * For example, a module providing an HTTP API may not expose entities of
  524. * this type or a custom entity reference field settings form may deprioritize
  525. * entities of this type in a select list.
  526. *
  527. * @return bool
  528. * TRUE if the entity data is internal, FALSE otherwise.
  529. *
  530. * @see \Drupal\Core\TypedData\DataDefinitionInterface::isInternal()
  531. */
  532. public function isInternal();
  533. /**
  534. * Indicates whether entities of this type have multilingual support.
  535. *
  536. * At an entity level, this indicates language support and at a bundle level
  537. * this indicates translation support.
  538. *
  539. * @return bool
  540. */
  541. public function isTranslatable();
  542. /**
  543. * Indicates whether the revision form fields should be added to the form.
  544. *
  545. * @return bool
  546. * TRUE if the form field should be added, FALSE otherwise.
  547. */
  548. public function showRevisionUi();
  549. /**
  550. * Indicates whether entities of this type have revision support.
  551. *
  552. * @return bool
  553. */
  554. public function isRevisionable();
  555. /**
  556. * Gets the name of the entity's revision data table.
  557. *
  558. * @todo Used by SqlContentEntityStorage only.
  559. *
  560. * @return string|null
  561. * The name of the entity type's revision data table, or NULL if none
  562. * exists.
  563. */
  564. public function getRevisionDataTable();
  565. /**
  566. * Gets the name of the entity's revision table.
  567. *
  568. * @todo Used by SqlContentEntityStorage only.
  569. *
  570. * @return string|null
  571. * The name of the entity type's revision table, or NULL if none exists.
  572. */
  573. public function getRevisionTable();
  574. /**
  575. * Gets the name of the entity's data table.
  576. *
  577. * @todo Used by SqlContentEntityStorage only.
  578. *
  579. * @return string|null
  580. * The name of the entity type's data table, or NULL if none exists.
  581. */
  582. public function getDataTable();
  583. /**
  584. * Gets the human-readable name of the entity type.
  585. *
  586. * This label should be used to present a human-readable name of the
  587. * entity type.
  588. *
  589. * @return string
  590. * The human-readable name of the entity type.
  591. */
  592. public function getLabel();
  593. /**
  594. * Gets the lowercase form of the human-readable entity type name.
  595. *
  596. * @return string
  597. * The lowercase form of the human-readable entity type name.
  598. *
  599. * @see \Drupal\Core\Entity\EntityTypeInterface::getLabel()
  600. */
  601. public function getLowercaseLabel();
  602. /**
  603. * Gets the uppercase plural form of the name of the entity type.
  604. *
  605. * This should return a human-readable version of the name that can refer
  606. * to all the entities of the given type, collectively. An example usage of
  607. * this is the page title of a page devoted to a collection of entities such
  608. * as "Workflows" (instead of "Workflow entities").
  609. *
  610. * @return string
  611. * The collection label.
  612. */
  613. public function getCollectionLabel();
  614. /**
  615. * Gets the indefinite singular form of the name of the entity type.
  616. *
  617. * This should return the human-readable name for a single instance of
  618. * the entity type. For example: "opportunity" (with the plural as
  619. * "opportunities"), "child" (with the plural as "children"), or "content
  620. * item" (with the plural as "content items").
  621. *
  622. * @return string
  623. * The singular label.
  624. */
  625. public function getSingularLabel();
  626. /**
  627. * Gets the indefinite plural form of the name of the entity type.
  628. *
  629. * This should return the human-readable name for more than one instance of
  630. * the entity type. For example: "opportunities" (with the singular as
  631. * "opportunity"), "children" (with the singular as "child"), or "content
  632. * items" (with the singular as "content item").
  633. *
  634. * @return string
  635. * The plural label.
  636. */
  637. public function getPluralLabel();
  638. /**
  639. * Gets the label's definite article form for use with a count of entities.
  640. *
  641. * This label should be used when the quantity of entities is provided. The
  642. * name should be returned in a form usable with a count of the
  643. * entities. For example: "1 opportunity", "5 opportunities", "1 child",
  644. * "6 children", "1 content item", "25 content items".
  645. *
  646. * @param int $count
  647. * The item count to display if the plural form was requested.
  648. *
  649. * @return string
  650. * The count label.
  651. */
  652. public function getCountLabel($count);
  653. /**
  654. * Gets a callable that can be used to provide the entity URI.
  655. *
  656. * This is only called if there is no matching link template for the link
  657. * relationship type, and there is no bundle-specific callback provided.
  658. *
  659. * @return callable|null
  660. * A valid callback that is passed the entity or NULL if none is specified.
  661. */
  662. public function getUriCallback();
  663. /**
  664. * Sets a callable to use to provide the entity URI.
  665. *
  666. * @param callable $callback
  667. * A callback to use to provide a URI for the entity.
  668. *
  669. * @return $this
  670. */
  671. public function setUriCallback($callback);
  672. /**
  673. * Gets the machine name of the entity type group.
  674. *
  675. * @return string
  676. */
  677. public function getGroup();
  678. /**
  679. * Gets the human-readable name of the entity type group.
  680. *
  681. * @return string
  682. */
  683. public function getGroupLabel();
  684. /**
  685. * The list cache contexts associated with this entity type.
  686. *
  687. * Enables code listing entities of this type to ensure that rendered listings
  688. * are varied as necessary, typically to ensure users of role A see other
  689. * entities listed than users of role B.
  690. *
  691. * @return string[]
  692. */
  693. public function getListCacheContexts();
  694. /**
  695. * The list cache tags associated with this entity type.
  696. *
  697. * Enables code listing entities of this type to ensure that newly created
  698. * entities show up immediately.
  699. *
  700. * @return string[]
  701. */
  702. public function getListCacheTags();
  703. /**
  704. * Gets the key that is used to store configuration dependencies.
  705. *
  706. * @return string
  707. * The key to be used in configuration dependencies when storing
  708. * dependencies on entities of this type.
  709. */
  710. public function getConfigDependencyKey();
  711. /**
  712. * Indicates whether this entity type is commonly used as a reference target.
  713. *
  714. * @return bool
  715. * TRUE if the entity type is a common reference; FALSE otherwise.
  716. */
  717. public function isCommonReferenceTarget();
  718. /**
  719. * Gets an array of validation constraints.
  720. *
  721. * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
  722. * details on how constraints are defined.
  723. *
  724. * @return array[]
  725. * An array of validation constraint definitions, keyed by constraint name.
  726. * Each constraint definition can be used for instantiating
  727. * \Symfony\Component\Validator\Constraint objects.
  728. *
  729. * @see \Symfony\Component\Validator\Constraint
  730. */
  731. public function getConstraints();
  732. /**
  733. * Sets the array of validation constraints for the FieldItemList.
  734. *
  735. * NOTE: This will overwrite any previously set constraints. In most cases
  736. * ContentEntityTypeInterface::addConstraint() should be used instead.
  737. * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
  738. * details on how constraints are defined.
  739. *
  740. * @param array $constraints
  741. * An array of validation constraint definitions, keyed by constraint name.
  742. * Each constraint definition can be used for instantiating
  743. * \Symfony\Component\Validator\Constraint objects.
  744. *
  745. * @return $this
  746. *
  747. * @see \Symfony\Component\Validator\Constraint
  748. */
  749. public function setConstraints(array $constraints);
  750. /**
  751. * Adds a validation constraint.
  752. *
  753. * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
  754. * details on how constraints are defined.
  755. *
  756. * @param string $constraint_name
  757. * The name of the constraint to add, i.e. its plugin id.
  758. * @param array|null $options
  759. * The constraint options as required by the constraint plugin, or NULL.
  760. *
  761. * @return $this
  762. */
  763. public function addConstraint($constraint_name, $options = NULL);
  764. /**
  765. * Gets the config dependency info for this entity, if any exists.
  766. *
  767. * @param string $bundle
  768. * The bundle name.
  769. *
  770. * @return array
  771. * An associative array containing the following keys:
  772. * - 'type': The config dependency type (e.g. 'module', 'config').
  773. * - 'name': The name of the config dependency.
  774. */
  775. public function getBundleConfigDependency($bundle);
  776. }