3 namespace Drupal\Core\Entity;
6 * Defines the interface for entity storage classes.
8 * For common default implementations, see
9 * \Drupal\Core\Entity\Sql\SqlContentEntityStorage for content entities and
10 * \Drupal\Core\Config\Entity\ConfigEntityStorage for config entities. Those
11 * implementations are used by default when the @ContentEntityType or
12 * @ConfigEntityType annotations are used.
16 interface EntityStorageInterface {
19 * Load the most recent version of an entity's field data.
21 const FIELD_LOAD_CURRENT = 'FIELD_LOAD_CURRENT';
24 * Load the version of an entity's field data specified in the entity.
26 const FIELD_LOAD_REVISION = 'FIELD_LOAD_REVISION';
29 * Resets the internal, static entity cache.
32 * (optional) If specified, the cache is reset for the entities with the
35 public function resetCache(array $ids = NULL);
38 * Loads one or more entities.
41 * An array of entity IDs, or NULL to load all entities.
43 * @return \Drupal\Core\Entity\EntityInterface[]
44 * An array of entity objects indexed by their IDs. Returns an empty array
45 * if no matching entities are found.
47 public function loadMultiple(array $ids = NULL);
53 * The ID of the entity to load.
55 * @return \Drupal\Core\Entity\EntityInterface|null
56 * An entity object. NULL if no matching entity is found.
58 public function load($id);
61 * Loads an unchanged entity from the database.
64 * The ID of the entity to load.
66 * @return \Drupal\Core\Entity\EntityInterface|null
67 * The unchanged entity, or NULL if the entity cannot be loaded.
69 * @todo Remove this method once we have a reliable way to retrieve the
70 * unchanged entity from the entity object.
72 public function loadUnchanged($id);
75 * Load a specific entity revision.
77 * @param int|string $revision_id
80 * @return \Drupal\Core\Entity\EntityInterface|null
81 * The specified entity revision or NULL if not found.
83 public function loadRevision($revision_id);
86 * Delete a specific entity revision.
88 * A revision can only be deleted if it's not the currently active one.
90 * @param int $revision_id
93 public function deleteRevision($revision_id);
96 * Load entities by their property values.
98 * @param array $values
99 * An associative array where the keys are the property names and the
100 * values are the values those properties must have.
102 * @return \Drupal\Core\Entity\EntityInterface[]
103 * An array of entity objects indexed by their ids.
105 public function loadByProperties(array $values = []);
108 * Constructs a new entity object, without permanently saving it.
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.
114 * @return \Drupal\Core\Entity\EntityInterface
115 * A new entity object.
117 public function create(array $values = []);
120 * Deletes permanently saved entities.
122 * @param array $entities
123 * An array of entity objects to delete.
125 * @throws \Drupal\Core\Entity\EntityStorageException
126 * In case of failures, an exception is thrown.
128 public function delete(array $entities);
131 * Saves the entity permanently.
133 * @param \Drupal\Core\Entity\EntityInterface $entity
134 * The entity to save.
137 * SAVED_NEW or SAVED_UPDATED is returned depending on the operation
140 * @throws \Drupal\Core\Entity\EntityStorageException
141 * In case of failures, an exception is thrown.
143 public function save(EntityInterface $entity);
146 * Gets an entity query instance.
148 * @param string $conjunction
149 * (optional) The logical operator for the query, either:
150 * - AND: all of the conditions on the query need to match.
151 * - OR: at least one of the conditions on the query need to match.
153 * @return \Drupal\Core\Entity\Query\QueryInterface
154 * The query instance.
156 * @see \Drupal\Core\Entity\EntityStorageBase::getQueryServiceName()
158 public function getQuery($conjunction = 'AND');
161 * Gets an aggregated query instance.
163 * @param string $conjunction
164 * (optional) The logical operator for the query, either:
165 * - AND: all of the conditions on the query need to match.
166 * - OR: at least one of the conditions on the query need to match.
168 * @return \Drupal\Core\Entity\Query\QueryAggregateInterface
169 * The aggregated query object that can query the given entity type.
171 * @see \Drupal\Core\Entity\EntityStorageBase::getQueryServiceName()
173 public function getAggregateQuery($conjunction = 'AND');
176 * Gets the entity type ID.
179 * The entity type ID.
181 public function getEntityTypeId();
184 * Gets the entity type definition.
186 * @return \Drupal\Core\Entity\EntityTypeInterface
187 * Entity type definition.
189 public function getEntityType();