EntityFieldManagerInterface.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace Drupal\Core\Entity;
  3. /**
  4. * Provides an interface for an entity field manager.
  5. */
  6. interface EntityFieldManagerInterface {
  7. /**
  8. * Gets the base field definitions for a content entity type.
  9. *
  10. * Only fields that are not specific to a given bundle or set of bundles are
  11. * returned. This excludes configurable fields, as they are always attached
  12. * to a specific bundle.
  13. *
  14. * @param string $entity_type_id
  15. * The entity type ID. Only entity types that implement
  16. * \Drupal\Core\Entity\FieldableEntityInterface are supported.
  17. *
  18. * @return \Drupal\Core\Field\FieldDefinitionInterface[]
  19. * The array of base field definitions for the entity type, keyed by field
  20. * name.
  21. *
  22. * @throws \LogicException
  23. * Thrown if one of the entity keys is flagged as translatable.
  24. */
  25. public function getBaseFieldDefinitions($entity_type_id);
  26. /**
  27. * Gets the field definitions for a specific bundle.
  28. *
  29. * @param string $entity_type_id
  30. * The entity type ID. Only entity types that implement
  31. * \Drupal\Core\Entity\FieldableEntityInterface are supported.
  32. * @param string $bundle
  33. * The bundle.
  34. *
  35. * @return \Drupal\Core\Field\FieldDefinitionInterface[]
  36. * The array of field definitions for the bundle, keyed by field name.
  37. */
  38. public function getFieldDefinitions($entity_type_id, $bundle);
  39. /**
  40. * Gets the field storage definitions for a content entity type.
  41. *
  42. * This returns all field storage definitions for base fields and bundle
  43. * fields of an entity type. Note that field storage definitions of a base
  44. * field equal the full base field definition (i.e. they implement
  45. * FieldDefinitionInterface), while the storage definitions for bundle fields
  46. * may implement FieldStorageDefinitionInterface only.
  47. *
  48. * @param string $entity_type_id
  49. * The entity type ID. Only content entities are supported.
  50. *
  51. * @return \Drupal\Core\Field\FieldStorageDefinitionInterface[]
  52. * The array of field storage definitions for the entity type, keyed by
  53. * field name.
  54. *
  55. * @see \Drupal\Core\Field\FieldStorageDefinitionInterface
  56. */
  57. public function getFieldStorageDefinitions($entity_type_id);
  58. /**
  59. * Gets a lightweight map of fields across bundles.
  60. *
  61. * @return array
  62. * An array keyed by entity type. Each value is an array which keys are
  63. * field names and value is an array with two entries:
  64. * - type: The field type.
  65. * - bundles: An associative array of the bundles in which the field
  66. * appears, where the keys and values are both the bundle's machine name.
  67. */
  68. public function getFieldMap();
  69. /**
  70. * Sets a lightweight map of fields across bundles.
  71. *
  72. * @param array[] $field_map
  73. * See the return value of self::getFieldMap().
  74. *
  75. * @return $this
  76. */
  77. public function setFieldMap(array $field_map);
  78. /**
  79. * Gets a lightweight map of fields across bundles filtered by field type.
  80. *
  81. * @param string $field_type
  82. * The field type to filter by.
  83. *
  84. * @return array
  85. * An array keyed by entity type. Each value is an array which keys are
  86. * field names and value is an array with two entries:
  87. * - type: The field type.
  88. * - bundles: An associative array of the bundles in which the field
  89. * appears, where the keys and values are both the bundle's machine name.
  90. */
  91. public function getFieldMapByFieldType($field_type);
  92. /**
  93. * Clears static and persistent field definition caches.
  94. */
  95. public function clearCachedFieldDefinitions();
  96. /**
  97. * Disable the use of caches.
  98. *
  99. * @param bool $use_caches
  100. * FALSE to not use any caches.
  101. *
  102. * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
  103. *
  104. * @todo Remove in https://www.drupal.org/node/2549143.
  105. */
  106. public function useCaches($use_caches = FALSE);
  107. /**
  108. * Gets the "extra fields" for a bundle.
  109. *
  110. * @param string $entity_type_id
  111. * The entity type ID.
  112. * @param string $bundle
  113. * The bundle name.
  114. *
  115. * @return array
  116. * A nested array of 'pseudo-field' elements. Each list is nested within the
  117. * following keys: entity type, bundle name, context (either 'form' or
  118. * 'display'). The keys are the name of the elements as appearing in the
  119. * renderable array (either the entity form or the displayed entity). The
  120. * value is an associative array:
  121. * - label: The human readable name of the element. Make sure you sanitize
  122. * this appropriately.
  123. * - description: A short description of the element contents.
  124. * - weight: The default weight of the element.
  125. * - visible: (optional) The default visibility of the element. Defaults to
  126. * TRUE.
  127. * - edit: (optional) String containing markup (normally a link) used as the
  128. * element's 'edit' operation in the administration interface. Only for
  129. * 'form' context.
  130. * - delete: (optional) String containing markup (normally a link) used as the
  131. * element's 'delete' operation in the administration interface. Only for
  132. * 'form' context.
  133. */
  134. public function getExtraFields($entity_type_id, $bundle);
  135. }