interface FieldableEntityStorageInterface implements EntityStorageInterface (View source)

A storage that supports entity types with field definitions.

Methods

resetCache(array $ids = NULL)

Resets the internal entity cache.

loadMultiple(array $ids = NULL)

Loads one or more entities.

load(mixed $id)

Loads one entity.

loadUnchanged(mixed $id)

Loads an unchanged entity from the database.

loadRevision(int|string $revision_id)

Load a specific entity revision.

deleteRevision(int $revision_id)

Delete a specific entity revision.

loadByProperties(array $values = [])

Load entities by their property values.

create(array $values = [])

Constructs a new entity object, without permanently saving it.

delete(array $entities)

Deletes permanently saved entities.

SAVED_NEW
save(EntityInterface $entity)

Saves the entity permanently.

restore(EntityInterface $entity)

Restores a previously saved entity.

bool
hasData()

Determines if the storage contains any data.

getQuery(string $conjunction = 'AND')

Gets an entity query instance.

getAggregateQuery(string $conjunction = 'AND')

Gets an aggregated query instance.

string
getEntityTypeId()

Gets the entity type ID.

getEntityType()

Gets the entity type definition.

string
getEntityClass(string|null $bundle = NULL)

Retrieves the class name used to create the entity.

bool|int
countFieldData(FieldStorageDefinitionInterface $storage_definition, bool $as_bool = FALSE)

Determines the number of entities with values for a given field.

int
purgeFieldData(FieldDefinitionInterface $field_definition, int $batch_size)

Purges a batch of field data.

finalizePurge(FieldStorageDefinitionInterface $storage_definition)

Performs final cleanup after all data of a field has been purged.

Details

resetCache(array $ids = NULL)

Resets the internal entity cache.

Parameters

array $ids

(optional) If specified, the cache is reset for the entities with the given ids only.

EntityInterface[] loadMultiple(array $ids = NULL)

Loads one or more entities.

Parameters

array $ids

An array of entity IDs, or NULL to load all entities.

Return Value

EntityInterface[]

An array of entity objects indexed by their IDs. Returns an empty array if no matching entities are found.

EntityInterface|null load(mixed $id)

Loads one entity.

Parameters

mixed $id

The ID of the entity to load.

Return Value

EntityInterface|null

An entity object. NULL if no matching entity is found.

EntityInterface|null loadUnchanged(mixed $id)

Loads an unchanged entity from the database.

Remove this method once we have a reliable way to retrieve the unchanged entity from the entity object.

Parameters

mixed $id

The ID of the entity to load.

Return Value

EntityInterface|null

The unchanged entity, or NULL if the entity cannot be loaded.

EntityInterface|null loadRevision(int|string $revision_id)

Load a specific entity revision.

Deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\RevisionableStorageInterface instead.

Parameters

int|string $revision_id

The revision id.

Return Value

EntityInterface|null

The specified entity revision or NULL if not found.

See also

https://www.drupal.org/node/2926958
https://www.drupal.org/node/2927226

deleteRevision(int $revision_id)

Delete a specific entity revision.

A revision can only be deleted if it's not the currently active one.

Deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\RevisionableStorageInterface instead.

Parameters

int $revision_id

The revision id.

See also

https://www.drupal.org/node/2926958
https://www.drupal.org/node/2927226

EntityInterface[] loadByProperties(array $values = [])

Load entities by their property values.

Parameters

array $values

An associative array where the keys are the property names and the values are the values those properties must have.

Return Value

EntityInterface[]

An array of entity objects indexed by their ids.

EntityInterface create(array $values = [])

Constructs a new entity object, without permanently saving it.

Parameters

array $values

(optional) An array of values to set, keyed by property name. If the entity type has bundles, the bundle key has to be specified.

Return Value

EntityInterface

A new entity object.

delete(array $entities)

Deletes permanently saved entities.

Parameters

array $entities

An array of entity objects to delete.

Exceptions

EntityStorageException

SAVED_NEW save(EntityInterface $entity)

Saves the entity permanently.

Parameters

EntityInterface $entity

The entity to save.

Return Value

SAVED_NEW

or SAVED_UPDATED is returned depending on the operation performed.

Exceptions

EntityStorageException

restore(EntityInterface $entity)

internal  This method should never be used to perform a regular entity save. Its only use-case is to assist updating entity types when there are complex schema changes, for example, to make them revisionable. Note that overriding this method to fix data prior to restoring is a likely sign that the current data is corrupt.
 

Restores a previously saved entity.

Note that the entity is assumed to be in a valid state for the storage, so the restore process does not invoke any hooks, nor does it perform any pre or post-save operations.

Parameters

EntityInterface $entity

The entity to restore.

Exceptions

EntityStorageException

bool hasData()

Determines if the storage contains any data.

Return Value

bool

TRUE if the storage contains data, FALSE if not.

QueryInterface getQuery(string $conjunction = 'AND')

Gets an entity query instance.

Parameters

string $conjunction

(optional) The logical operator for the query, either:

  • AND: all of the conditions on the query need to match.
  • OR: at least one of the conditions on the query need to match.

Return Value

QueryInterface

The query instance.

See also

EntityStorageBase::getQueryServiceName

QueryAggregateInterface getAggregateQuery(string $conjunction = 'AND')

Gets an aggregated query instance.

Parameters

string $conjunction

(optional) The logical operator for the query, either:

  • AND: all of the conditions on the query need to match.
  • OR: at least one of the conditions on the query need to match.

Return Value

QueryAggregateInterface

The aggregated query object that can query the given entity type.

See also

EntityStorageBase::getQueryServiceName

string getEntityTypeId()

Gets the entity type ID.

Return Value

string

The entity type ID.

EntityTypeInterface getEntityType()

Gets the entity type definition.

Return Value

EntityTypeInterface

Entity type definition.

string getEntityClass(string|null $bundle = NULL)

Retrieves the class name used to create the entity.

Parameters

string|null $bundle

(optional) A specific entity type bundle identifier. Can be omitted in the case of entity types without bundles, like User.

Return Value

string

The entity class name.

bool|int countFieldData(FieldStorageDefinitionInterface $storage_definition, bool $as_bool = FALSE)

Determines the number of entities with values for a given field.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field for which to count data records.

bool $as_bool

(Optional) Optimizes the query for checking whether there are any records or not. Defaults to FALSE.

Return Value

bool|int

The number of entities. If $as_bool parameter is TRUE then the value will either be TRUE or FALSE.

See also

FieldableEntityStorageInterface::purgeFieldData

int purgeFieldData(FieldDefinitionInterface $field_definition, int $batch_size)

Purges a batch of field data.

Parameters

FieldDefinitionInterface $field_definition

The deleted field whose data is being purged.

int $batch_size

The maximum number of field data records to purge before returning, relating to the count of field data records returned by \Drupal\Core\Entity\FieldableEntityStorageInterface::countFieldData().

Return Value

int

The number of field data records that have been purged.

finalizePurge(FieldStorageDefinitionInterface $storage_definition)

Performs final cleanup after all data of a field has been purged.

Parameters

FieldStorageDefinitionInterface $storage_definition

The field storage being purged.