interface TermStorageInterface implements ContentEntityStorageInterface (View source)

Defines an interface for taxonomy_term entity storage classes.

Methods

resetCache(array $ids = NULL)

Resets the internal, static 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.

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.

deleteTermHierarchy(array $tids)

Removed reference to terms from term_hierarchy.

updateTermHierarchy(EntityInterface $term)

Updates terms hierarchy information with the hierarchy trail of it.

loadParents(int $tid)

Finds all parents of a given term ID.

loadAllParents(int $tid)

Finds all ancestors of a given term ID.

loadChildren(int $tid, string $vid = NULL)

Finds all children of a term ID.

object[]|TermInterface[]
loadTree(string $vid, int $parent = 0, int $max_depth = NULL, bool $load_entities = FALSE)

Finds all terms in a given vocabulary ID.

int
nodeCount(string $vid)

Count the number of nodes in a given vocabulary ID.

resetWeights(string $vid)

Reset the weights for a given vocabulary ID.

array
getNodeTerms(array $nids, array $vocabs = [], string $langcode = NULL)

Returns all terms used to tag some given nodes.

int
getVocabularyHierarchyType(string $vid)

Returns the hierarchy type for a specific vocabulary ID.

int[]
getTermIdsWithPendingRevisions()

Gets a list of term IDs with pending revisions.

Details

resetCache(array $ids = NULL)

Resets the internal, static 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.

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

deleteTermHierarchy(array $tids)

Removed reference to terms from term_hierarchy.

Remove this method in Drupal 9.0.x. Now the parent references are automatically cleared when deleting a taxonomy term. https://www.drupal.org/node/2785693

Parameters

array $tids

Array of terms that need to be removed from hierarchy.

updateTermHierarchy(EntityInterface $term)

Updates terms hierarchy information with the hierarchy trail of it.

remove this method Drupal 9.0.x. Now the parent references are automatically updates when when a taxonomy term is added/updated. https://www.drupal.org/node/2785693

Parameters

EntityInterface $term

Term entity that needs to be added to term hierarchy information.

TermInterface[] loadParents(int $tid)

Finds all parents of a given term ID.

Parameters

int $tid

Term ID to retrieve parents for.

Return Value

TermInterface[]

An array of term objects which are the parents of the term $tid.

TermInterface[] loadAllParents(int $tid)

Finds all ancestors of a given term ID.

Parameters

int $tid

Term ID to retrieve ancestors for.

Return Value

TermInterface[]

An array of term objects which are the ancestors of the term $tid.

TermInterface[] loadChildren(int $tid, string $vid = NULL)

Finds all children of a term ID.

Parameters

int $tid

Term ID to retrieve children for.

string $vid

An optional vocabulary ID to restrict the child search.

Return Value

TermInterface[]

An array of term objects that are the children of the term $tid.

object[]|TermInterface[] loadTree(string $vid, int $parent = 0, int $max_depth = NULL, bool $load_entities = FALSE)

Finds all terms in a given vocabulary ID.

Parameters

string $vid

Vocabulary ID to retrieve terms for.

int $parent

The term ID under which to generate the tree. If 0, generate the tree for the entire vocabulary.

int $max_depth

The number of levels of the tree to return. Leave NULL to return all levels.

bool $load_entities

If TRUE, a full entity load will occur on the term objects. Otherwise they are partial objects queried directly from the {taxonomy_term_data} table to save execution time and memory consumption when listing large numbers of terms. Defaults to FALSE.

Return Value

object[]|TermInterface[]

An array of term objects that are the children of the vocabulary $vid.

int nodeCount(string $vid)

Count the number of nodes in a given vocabulary ID.

Parameters

string $vid

Vocabulary ID to retrieve terms for.

Return Value

int

A count of the nodes in a given vocabulary ID.

resetWeights(string $vid)

Reset the weights for a given vocabulary ID.

Parameters

string $vid

Vocabulary ID to retrieve terms for.

array getNodeTerms(array $nids, array $vocabs = [], string $langcode = NULL)

Returns all terms used to tag some given nodes.

Parameters

array $nids

Node IDs to retrieve terms for.

array $vocabs

(optional) A vocabularies array to restrict the term search. Defaults to empty array.

string $langcode

(optional) A language code to restrict the term search. Defaults to NULL.

Return Value

array

An array of nids and the term entities they were tagged with.

int getVocabularyHierarchyType(string $vid)

Returns the hierarchy type for a specific vocabulary ID.

Parameters

string $vid

Vocabulary ID to retrieve the hierarchy type for.

Return Value

int

The vocabulary hierarchy. Possible values:

  • VocabularyInterface::HIERARCHY_DISABLED: No parents.
  • VocabularyInterface::HIERARCHY_SINGLE: Single parent.
  • VocabularyInterface::HIERARCHY_MULTIPLE: Multiple parents.

int[] getTermIdsWithPendingRevisions()

internal  
 

Gets a list of term IDs with pending revisions.

Return Value

int[]

An array of term IDs which have pending revisions, keyed by their revision IDs.