interface UserStorageInterface implements ContentEntityStorageInterface (View source)

Defines an interface for user entity storage classes.

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.

createTranslation(ContentEntityInterface $entity, string $langcode, array $values = [])

Constructs a new entity translation object, without permanently saving it.

createRevision(RevisionableInterface $entity, bool $default = TRUE)

Creates a new revision starting off from the specified entity object.

loadMultipleRevisions(array $revision_ids)

Loads multiple entity revisions.

int|string|null
getLatestRevisionId(int|string $entity_id)

Returns the latest revision identifier for an entity.

int|string|null
getLatestTranslationAffectedRevisionId(int|string $entity_id, string $langcode)

Returns the latest revision affecting the specified translation.

createWithSampleValues(string|bool $bundle = FALSE, array $values = [])

Creates an entity with sample field values.

updateLastLoginTimestamp(UserInterface $account)

Update the last login timestamp of the user.

updateLastAccessTimestamp(AccountInterface $account, int $timestamp)

Update the last access timestamp of the user.

deleteRoleReferences(array $rids)

Delete role references.

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.

ContentEntityInterface createTranslation(ContentEntityInterface $entity, string $langcode, array $values = [])

Constructs a new entity translation object, without permanently saving it.

Consider accepting \Drupal\Core\Entity\TranslatableInterface as first parameter. See https://www.drupal.org/project/drupal/issues/2932049.

Parameters

ContentEntityInterface $entity

The entity object being translated.

string $langcode

The translation language code.

array $values

(optional) An associative array of initial field values keyed by field name. If none is provided default values will be applied.

Return Value

ContentEntityInterface

Another instance of the specified entity object class with the specified active language and initial values.

RevisionableInterface createRevision(RevisionableInterface $entity, bool $default = TRUE)

Creates a new revision starting off from the specified entity object.

Parameters

RevisionableInterface $entity

The revisionable entity object being modified.

bool $default

(optional) Whether the new revision should be marked as default. Defaults to TRUE.

Return Value

RevisionableInterface

A new entity revision object.

RevisionableInterface[] loadMultipleRevisions(array $revision_ids)

Loads multiple entity revisions.

Parameters

array $revision_ids

An array of revision IDs to load.

Return Value

RevisionableInterface[]

An array of entity revisions keyed by their revision ID, or an empty array if none found.

int|string|null getLatestRevisionId(int|string $entity_id)

Returns the latest revision identifier for an entity.

Parameters

int|string $entity_id

The entity identifier.

Return Value

int|string|null

The latest revision identifier or NULL if no revision could be found.

int|string|null getLatestTranslationAffectedRevisionId(int|string $entity_id, string $langcode)

Returns the latest revision affecting the specified translation.

Parameters

int|string $entity_id

The entity identifier.

string $langcode

The language code of the translation.

Return Value

int|string|null

A revision ID or NULL if no revision affecting the specified translation could be found.

FieldableEntityInterface createWithSampleValues(string|bool $bundle = FALSE, array $values = [])

Creates an entity with sample field values.

Parameters

string|bool $bundle

(optional) The entity bundle.

array $values

(optional) Any default values to use during generation.

Return Value

FieldableEntityInterface

A fieldable content entity.

Exceptions

EntityStorageException

updateLastLoginTimestamp(UserInterface $account)

Update the last login timestamp of the user.

Parameters

UserInterface $account

The user account.

updateLastAccessTimestamp(AccountInterface $account, int $timestamp)

Update the last access timestamp of the user.

Parameters

AccountInterface $account

The user object.

int $timestamp

The last access timestamp.

deleteRoleReferences(array $rids)

Delete role references.

Parameters

array $rids

The list of role IDs being deleted. The storage should remove permission and user references to this role.