EntityStorageInterface.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. namespace Drupal\Core\Entity;
  3. /**
  4. * Defines the interface for entity storage classes.
  5. *
  6. * For common default implementations, see
  7. * \Drupal\Core\Entity\Sql\SqlContentEntityStorage for content entities and
  8. * \Drupal\Core\Config\Entity\ConfigEntityStorage for config entities. Those
  9. * implementations are used by default when the @ContentEntityType or
  10. * @ConfigEntityType annotations are used.
  11. *
  12. * @ingroup entity_api
  13. */
  14. interface EntityStorageInterface {
  15. /**
  16. * Load the most recent version of an entity's field data.
  17. */
  18. const FIELD_LOAD_CURRENT = 'FIELD_LOAD_CURRENT';
  19. /**
  20. * Load the version of an entity's field data specified in the entity.
  21. */
  22. const FIELD_LOAD_REVISION = 'FIELD_LOAD_REVISION';
  23. /**
  24. * Resets the internal, static entity cache.
  25. *
  26. * @param $ids
  27. * (optional) If specified, the cache is reset for the entities with the
  28. * given ids only.
  29. */
  30. public function resetCache(array $ids = NULL);
  31. /**
  32. * Loads one or more entities.
  33. *
  34. * @param $ids
  35. * An array of entity IDs, or NULL to load all entities.
  36. *
  37. * @return \Drupal\Core\Entity\EntityInterface[]
  38. * An array of entity objects indexed by their IDs. Returns an empty array
  39. * if no matching entities are found.
  40. */
  41. public function loadMultiple(array $ids = NULL);
  42. /**
  43. * Loads one entity.
  44. *
  45. * @param mixed $id
  46. * The ID of the entity to load.
  47. *
  48. * @return \Drupal\Core\Entity\EntityInterface|null
  49. * An entity object. NULL if no matching entity is found.
  50. */
  51. public function load($id);
  52. /**
  53. * Loads an unchanged entity from the database.
  54. *
  55. * @param mixed $id
  56. * The ID of the entity to load.
  57. *
  58. * @return \Drupal\Core\Entity\EntityInterface|null
  59. * The unchanged entity, or NULL if the entity cannot be loaded.
  60. *
  61. * @todo Remove this method once we have a reliable way to retrieve the
  62. * unchanged entity from the entity object.
  63. */
  64. public function loadUnchanged($id);
  65. /**
  66. * Load a specific entity revision.
  67. *
  68. * @param int|string $revision_id
  69. * The revision id.
  70. *
  71. * @return \Drupal\Core\Entity\EntityInterface|null
  72. * The specified entity revision or NULL if not found.
  73. *
  74. * @todo Deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
  75. * Use \Drupal\Core\Entity\RevisionableStorageInterface instead.
  76. *
  77. * @see https://www.drupal.org/node/2926958
  78. * @see https://www.drupal.org/node/2927226
  79. */
  80. public function loadRevision($revision_id);
  81. /**
  82. * Delete a specific entity revision.
  83. *
  84. * A revision can only be deleted if it's not the currently active one.
  85. *
  86. * @param int $revision_id
  87. * The revision id.
  88. *
  89. * @todo Deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
  90. * Use \Drupal\Core\Entity\RevisionableStorageInterface instead.
  91. *
  92. * @see https://www.drupal.org/node/2926958
  93. * @see https://www.drupal.org/node/2927226
  94. */
  95. public function deleteRevision($revision_id);
  96. /**
  97. * Load entities by their property values.
  98. *
  99. * @param array $values
  100. * An associative array where the keys are the property names and the
  101. * values are the values those properties must have.
  102. *
  103. * @return \Drupal\Core\Entity\EntityInterface[]
  104. * An array of entity objects indexed by their ids.
  105. */
  106. public function loadByProperties(array $values = []);
  107. /**
  108. * Constructs a new entity object, without permanently saving it.
  109. *
  110. * @param array $values
  111. * (optional) An array of values to set, keyed by property name. If the
  112. * entity type has bundles, the bundle key has to be specified.
  113. *
  114. * @return \Drupal\Core\Entity\EntityInterface
  115. * A new entity object.
  116. */
  117. public function create(array $values = []);
  118. /**
  119. * Deletes permanently saved entities.
  120. *
  121. * @param array $entities
  122. * An array of entity objects to delete.
  123. *
  124. * @throws \Drupal\Core\Entity\EntityStorageException
  125. * In case of failures, an exception is thrown.
  126. */
  127. public function delete(array $entities);
  128. /**
  129. * Saves the entity permanently.
  130. *
  131. * @param \Drupal\Core\Entity\EntityInterface $entity
  132. * The entity to save.
  133. *
  134. * @return
  135. * SAVED_NEW or SAVED_UPDATED is returned depending on the operation
  136. * performed.
  137. *
  138. * @throws \Drupal\Core\Entity\EntityStorageException
  139. * In case of failures, an exception is thrown.
  140. */
  141. public function save(EntityInterface $entity);
  142. /**
  143. * Determines if the storage contains any data.
  144. *
  145. * @return bool
  146. * TRUE if the storage contains data, FALSE if not.
  147. */
  148. public function hasData();
  149. /**
  150. * Gets an entity query instance.
  151. *
  152. * @param string $conjunction
  153. * (optional) The logical operator for the query, either:
  154. * - AND: all of the conditions on the query need to match.
  155. * - OR: at least one of the conditions on the query need to match.
  156. *
  157. * @return \Drupal\Core\Entity\Query\QueryInterface
  158. * The query instance.
  159. *
  160. * @see \Drupal\Core\Entity\EntityStorageBase::getQueryServiceName()
  161. */
  162. public function getQuery($conjunction = 'AND');
  163. /**
  164. * Gets an aggregated query instance.
  165. *
  166. * @param string $conjunction
  167. * (optional) The logical operator for the query, either:
  168. * - AND: all of the conditions on the query need to match.
  169. * - OR: at least one of the conditions on the query need to match.
  170. *
  171. * @return \Drupal\Core\Entity\Query\QueryAggregateInterface
  172. * The aggregated query object that can query the given entity type.
  173. *
  174. * @see \Drupal\Core\Entity\EntityStorageBase::getQueryServiceName()
  175. */
  176. public function getAggregateQuery($conjunction = 'AND');
  177. /**
  178. * Gets the entity type ID.
  179. *
  180. * @return string
  181. * The entity type ID.
  182. */
  183. public function getEntityTypeId();
  184. /**
  185. * Gets the entity type definition.
  186. *
  187. * @return \Drupal\Core\Entity\EntityTypeInterface
  188. * Entity type definition.
  189. */
  190. public function getEntityType();
  191. }