EntityTypeInterface.php 27 KB

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