class Term extends EditorialContentEntityBase implements TermInterface (View source)

Defines the taxonomy term entity.

Traits

Provides a trait for accessing changed time.

Provides a trait for published status.

Provides a trait for accessing revision logging and ownership information.

Provides helper methods to detect changes in an entity object.

Provides a trait for accessing synchronization information.

Trait for \Drupal\Core\Cache\RefinableCacheableDependencyInterface.

Provides dependency injection friendly methods for serialization.

Trait for \Drupal\Core\Cache\CacheableDependencyInterface.

Properties

protected string[] $cacheContexts

Cache contexts.

from  CacheableDependencyTrait
protected string[] $cacheTags

Cache tags.

from  CacheableDependencyTrait
protected int $cacheMaxAge

Cache max-age.

from  CacheableDependencyTrait
protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected string $entityTypeId

The entity type.

from  EntityBase
protected bool $enforceIsNew

Boolean indicating whether the entity should be forced to be new.

from  EntityBase
protected ComplexDataInterface $typedData

A typed data object wrapping this entity.

from  EntityBase
protected bool $isSyncing

Whether this entity is being created, updated or deleted through a synchronization process.

from  SynchronizableEntityTrait
protected array $values

The plain data values of the contained fields.

from  ContentEntityBase
protected array $fields

The array of fields, each being an instance of FieldItemListInterface.

from  ContentEntityBase
protected array $fieldDefinitions

Local cache for field definitions.

from  ContentEntityBase
protected LanguageInterface[] $languages

Local cache for the available language objects.

from  ContentEntityBase
protected string $langcodeKey

The language entity key.

from  ContentEntityBase
protected string $defaultLangcodeKey

The default langcode entity key.

from  ContentEntityBase
protected string $activeLangcode

Language code identifying the entity active language.

from  ContentEntityBase
protected string $defaultLangcode

Local cache for the default language code.

from  ContentEntityBase
protected array $translations

An array of entity translation metadata.

from  ContentEntityBase
protected bool $translationInitialize

A flag indicating whether a translation object is being initialized.

from  ContentEntityBase
protected bool $newRevision

Boolean indicating whether a new revision should be created on save.

from  ContentEntityBase
protected bool $isDefaultRevision

Indicates whether this is the default revision.

from  ContentEntityBase
protected array $entityKeys

Holds untranslatable entity keys such as the ID, bundle, and revision ID.

from  ContentEntityBase
protected array $translatableEntityKeys

Holds translatable entity keys such as the label.

from  ContentEntityBase
protected bool $validated

Whether entity validation was performed.

from  ContentEntityBase
protected bool $validationRequired

Whether entity validation is required before saving the entity.

from  ContentEntityBase
protected int $loadedRevisionId

The loaded revision ID before the new revision was set.

from  ContentEntityBase
protected string $revisionTranslationAffectedKey

The revision translation affected entity key.

from  ContentEntityBase
protected bool[] $enforceRevisionTranslationAffected

Whether the revision translation affected flag has been enforced.

from  ContentEntityBase
static protected array $fieldsToSkipFromTranslationChangesCheck

Local cache for fields to skip from the checking for translation changes.

from  ContentEntityBase

Methods

$this
setCacheability(CacheableDependencyInterface $cacheability)

Sets cacheability; useful for value object constructors.

getCacheTags()

{@inheritdoc}

addCacheableDependency($other_object)

{@inheritdoc}

addCacheContexts(array $cache_contexts)

{@inheritdoc}

addCacheTags(array $cache_tags)

{@inheritdoc}

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(array $values, string $entity_type, $bundle = FALSE, $translations = [])

Constructs an Entity object.

entityTypeManager()

Gets the entity type manager.

entityTypeBundleInfo()

Gets the entity type bundle info service.

languageManager()

Gets the language manager.

uuidGenerator()

Gets the UUID generator.

string|int|null
id()

Gets the identifier.

string|null
uuid()

Gets the entity UUID (Universally Unique Identifier).

bool
isNew()

Determines whether the entity is new.

$this
enforceIsNew(bool $value = TRUE)

Enforces an entity to be new.

string
getEntityTypeId()

Gets the ID of the type of the entity.

string
bundle()

Gets the bundle of the entity.

string|TranslatableMarkup|null
label()

Gets the label of the entity.

Url
toUrl(string $rel = 'canonical', array $options = [])

Gets the URL object for the entity.

bool
hasLinkTemplate($rel)

Indicates if a link template exists for a given key.

array
linkTemplates()

Gets an array link templates.

toLink(string|null $text = NULL, string $rel = 'canonical', array $options = [])

Generates the HTML for a link to this entity.

array
urlRouteParameters(string $rel)

Gets an array of placeholders for this entity.

string[]
uriRelationships()

Gets a list of URI relationships supported by this entity.

access(string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)

Checks data value access.

language()

Gets the language of the entity.

int
save()

Saves an entity permanently.

delete()

Deletes an entity permanently.

createDuplicate()

Creates a duplicate of the entity.

getEntityType()

Gets the entity type definition.

preSave(EntityStorageInterface $storage)

Acts on an entity before the presave hook is invoked.

postSave(EntityStorageInterface $storage, bool $update = TRUE)

Acts on a saved entity before the insert or update hook is invoked.

static 
preCreate(EntityStorageInterface $storage, array $values)

Changes the values of an entity before it is created.

postCreate(EntityStorageInterface $storage)

Acts on a created entity before hooks are invoked.

static 
preDelete(EntityStorageInterface $storage, array $entities)

Acts on entities before they are deleted and before hooks are invoked.

static 
postDelete(EntityStorageInterface $storage, array $entities)

Acts on deleted entities before the delete hook is invoked.

static 
postLoad(EntityStorageInterface $storage, array $entities)

Acts on loaded entities.

referencedEntities()

Gets a list of entities referenced by this entity.

string[]
getListCacheTagsToInvalidate()

The list cache tags to invalidate for this entity.

string[]
getCacheTagsToInvalidate()

Returns the cache tags that should be used to invalidate caches.

static EntityInterface|null
load(mixed $id)

Loads an entity.

static EntityInterface[]
loadMultiple(array $ids = NULL)

Loads one or more entities.

static EntityInterface
create(array $values = [])

Constructs a new entity object, without permanently saving it.

invalidateTagsOnSave(bool $update)

Invalidates an entity's cache tags upon save.

static 
invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities)

Invalidates an entity's cache tags upon delete.

int|string|null
getOriginalId()

Gets the original ID.

$this
setOriginalId(int|string|null $id)

Sets the original ID.

array
toArray()

Gets an array of all property values.

getTypedData()

Gets a typed data object for this entity object.

string
getConfigDependencyKey()

Gets the key that is used to store configuration dependencies.

string
getConfigDependencyName()

Gets the configuration dependency name.

string
getConfigTarget()

Gets the configuration target identifier for the entity.

string[]
getFieldsToSkipFromTranslationChangesCheck(ContentEntityInterface $entity)

Returns an array of field names to skip when checking for changes.

setSyncing($syncing)

{@inheritdoc}

isSyncing()

{@inheritdoc}

getLanguages()

{@inheritdoc}

setNewRevision(bool $value = TRUE)

Enforces an entity to be saved as a new revision.

int
getLoadedRevisionId()

Gets the loaded Revision ID of the entity.

$this
updateLoadedRevisionId()

Updates the loaded Revision ID with the revision ID.

bool
isNewRevision()

Determines whether a new revision should be created on save.

bool
isDefaultRevision(bool $new_value = NULL)

Checks if this entity is the default revision.

bool
wasDefaultRevision()

Checks whether the entity object was a default revision when it was saved.

bool
isLatestRevision()

Checks if this entity is the latest revision.

bool
isLatestTranslationAffectedRevision()

Checks whether this is the latest revision affecting this translation.

bool
isRevisionTranslationAffected()

Checks whether the current translation is affected by the current revision.

$this
setRevisionTranslationAffected(bool|null $affected)

Marks the current revision translation as affected.

bool
isRevisionTranslationAffectedEnforced()

Checks if the revision translation affected flag value has been enforced.

$this
setRevisionTranslationAffectedEnforced(bool $enforced)

Enforces the revision translation affected flag value.

bool
isDefaultTranslation()

Checks whether the translation is the default one.

The
getRevisionId()

Gets the revision identifier of the entity.

bool
isTranslatable()

Returns the translation support status.

preSaveRevision(EntityStorageInterface $storage, stdClass $record)

Acts on a revision before it gets saved.

validate()

Validates the currently set values.

bool
isValidationRequired()

Checks whether entity validation is required before saving the entity.

$this
setValidationRequired(bool $required)

Sets whether entity validation is required before saving the entity.

clearTranslationCache()

Clear entity translation object cache to remove stale references.

bool
hasField(string $field_name)

Determines whether the entity has a field with the given name.

get(string $field_name)

Gets a field item list.

getTranslatedField($name, $langcode)

Gets a translated field.

$this
set($name, mixed $value, bool $notify = TRUE)

Sets a field value.

getFields(bool $include_computed = TRUE)

Gets an array of all field item lists.

getTranslatableFields(bool $include_computed = TRUE)

Gets an array of field item lists for translatable fields.

getIterator()

{@inheritdoc}

getFieldDefinition(string $name)

Gets the definition of a contained field.

getFieldDefinitions()

Gets an array of field definitions of all contained fields.

setDefaultLangcode()

Populates the local cache for the default language code.

updateFieldLangcodes($langcode)

Updates language for already instantiated fields.

onChange($name)

Reacts to changes to a field.

$this
getTranslation($langcode)

Gets a translation of the data.

$this
getUntranslated()

Returns the translatable object referring to the original language.

initializeTranslation(string $langcode)

Instantiates a translation object for an existing translation.

bool
hasTranslation(string $langcode)

Checks there is a translation for the given language code.

bool
isNewTranslation()

Checks whether the translation is new.

$this
addTranslation(string $langcode, array $values = [])

Adds a new translation to the translatable object.

removeTranslation(string $langcode)

Removes the translation identified by the given language code.

int|null
getTranslationStatus(string $langcode)

Returns the translation status.

getTranslationLanguages(bool $include_default = TRUE)

Returns the languages the data is translated to.

updateOriginalValues()

Updates the original values with the interim changes.

__get($name)

Implements the magic method for getting object properties.

__set($name, $value)

Implements the magic method for setting object properties.

__isset($name)

Implements the magic method for isset().

__unset($name)

Implements the magic method for unset().

__clone()

Magic method: Implements a deep clone.

mixed
getEntityKey(string $key)

Gets the value of the given entity key, if defined.

baseFieldDefinitions(EntityTypeInterface $entity_type)

Provides base field definitions for an entity type.

bundleFieldDefinitions(EntityTypeInterface $entity_type, string $bundle, array $base_field_definitions)

Provides field definitions for a specific bundle.

bool
hasTranslationChanges()

Determines if the current translation of the entity has unsaved changes.

bool
isDefaultTranslationAffectedOnly()

Checks if untranslatable fields should affect only the default translation.

int
getChangedTimeAcrossTranslations()

Returns the timestamp of the last entity change across all translations.

int
getChangedTime()

Gets the timestamp of the last entity change for the current translation.

$this
setChangedTime(int $timestamp)

Sets the timestamp of the last entity change for the current translation.

publishedBaseFieldDefinitions(EntityTypeInterface $entity_type)

Returns an array of base field definitions for publishing status.

isPublished()

{@inheritdoc}

setPublished()

{@inheritdoc}

setUnpublished()

{@inheritdoc}

revisionLogBaseFieldDefinitions(EntityTypeInterface $entity_type)

Provides revision-related base field definitions for an entity type.

getRevisionCreationTime()

Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionCreationTime().

setRevisionCreationTime($timestamp)

Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionCreationTime().

getRevisionUser()

Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionUser().

setRevisionUser(UserInterface $account)

Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionUser().

getRevisionUserId()

Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionUserId().

setRevisionUserId($user_id)

Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionUserId().

getRevisionLogMessage()

Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionLogMessage().

setRevisionLogMessage($revision_log_message)

Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionLogMessage().

static string
getRevisionMetadataKey(EntityTypeInterface $entity_type, string $key)

Gets the name of a revision metadata field.

string
getDescription()

Gets the term description.

$this
setDescription(string $description)

Sets the term description.

string
getFormat()

Gets the text format name for the term description.

$this
setFormat(string $format)

Sets the text format name for the term description.

string
getName()

Gets the term name.

$this
setName(string $name)

Sets the term name.

int
getWeight()

Gets the term weight.

$this
setWeight(int $weight)

Sets the term weight.

Details

protected $this setCacheability(CacheableDependencyInterface $cacheability)

Sets cacheability; useful for value object constructors.

Parameters

CacheableDependencyInterface $cacheability

The cacheability to set.

Return Value

$this

getCacheTags()

{@inheritdoc}

getCacheContexts()

{@inheritdoc}

getCacheMaxAge()

{@inheritdoc}

addCacheableDependency($other_object)

{@inheritdoc}

Parameters

$other_object

addCacheContexts(array $cache_contexts)

{@inheritdoc}

Parameters

array $cache_contexts

addCacheTags(array $cache_tags)

{@inheritdoc}

Parameters

array $cache_tags

mergeCacheMaxAge($max_age)

{@inheritdoc}

Parameters

$max_age

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(array $values, string $entity_type, $bundle = FALSE, $translations = [])

Constructs an Entity object.

Parameters

array $values

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

string $entity_type

The type of the entity to create.

$bundle
$translations

protected EntityTypeManagerInterface entityTypeManager()

Gets the entity type manager.

protected EntityTypeBundleInfoInterface entityTypeBundleInfo()

Gets the entity type bundle info service.

protected LanguageManagerInterface languageManager()

Gets the language manager.

protected UuidInterface uuidGenerator()

Gets the UUID generator.

Return Value

UuidInterface

string|int|null id()

Gets the identifier.

Return Value

string|int|null

The entity identifier, or NULL if the object does not yet have an identifier.

string|null uuid()

Gets the entity UUID (Universally Unique Identifier).

The UUID is guaranteed to be unique and can be used to identify an entity across multiple systems.

Return Value

string|null

The UUID of the entity, or NULL if the entity does not have one.

bool isNew()

Determines whether the entity is new.

Usually an entity is new if no ID exists for it yet. However, entities may be enforced to be new with existing IDs too.

Return Value

bool

TRUE if the entity is new, or FALSE if the entity has already been saved.

$this enforceIsNew(bool $value = TRUE)

Enforces an entity to be new.

Allows migrations to create entities with pre-defined IDs by forcing the entity to be new before saving.

Parameters

bool $value

(optional) Whether the entity should be forced to be new. Defaults to TRUE.

Return Value

$this

string getEntityTypeId()

Gets the ID of the type of the entity.

Return Value

string

The entity type ID.

string bundle()

Gets the bundle of the entity.

Return Value

string

The bundle of the entity. Defaults to the entity type ID if the entity type does not make use of different bundles.

string|TranslatableMarkup|null label()

Gets the label of the entity.

Return Value

string|TranslatableMarkup|null

The label of the entity, or NULL if there is no label defined.

Url toUrl(string $rel = 'canonical', array $options = [])

Gets the URL object for the entity.

The entity must have an id already. Content entities usually get their IDs by saving them.

URI templates might be set in the links array in an annotation, for example:

Parameters

string $rel

The link relationship type, for example: canonical or edit-form.

array $options

See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for the available options.

Return Value

Url

The URL object.

Exceptions

EntityMalformedException
UndefinedLinkTemplateException

bool hasLinkTemplate($rel)

Indicates if a link template exists for a given key.

Parameters

$rel

Return Value

bool

TRUE if the link template exists, FALSE otherwise.

protected array linkTemplates()

Gets an array link templates.

Return Value

array

An array of link templates containing paths.

Generates the HTML for a link to this entity.

Parameters

string|null $text

(optional) The link text for the anchor tag as a translated string. If NULL, it will use the entity's label. Defaults to NULL.

string $rel

(optional) The link relationship type. Defaults to 'canonical'.

array $options

See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for the available options.

Return Value

Link

A Link to the entity.

Exceptions

EntityMalformedException
UndefinedLinkTemplateException

protected array urlRouteParameters(string $rel)

Gets an array of placeholders for this entity.

Individual entity classes may override this method to add additional placeholders if desired. If so, they should be sure to replicate the property caching logic.

Parameters

string $rel

The link relationship type, for example: canonical or edit-form.

Return Value

array

An array of URI placeholders.

string[] uriRelationships()

Gets a list of URI relationships supported by this entity.

Return Value

string[]

An array of link relationships supported by this entity.

bool|AccessResultInterface access(string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)

Checks data value access.

Parameters

string $operation

The operation to be performed.

AccountInterface $account

(optional) The user for which to check access, or NULL to check access for the current user. Defaults to NULL.

bool $return_as_object

(optional) Defaults to FALSE.

Return Value

bool|AccessResultInterface

The access result. Returns a boolean if $return_as_object is FALSE (this is the default) and otherwise an AccessResultInterface object. When a boolean is returned, the result of AccessInterface::isAllowed() is returned, i.e. TRUE means access is explicitly allowed, FALSE means access is either explicitly forbidden or "no opinion".

LanguageInterface language()

Gets the language of the entity.

Return Value

LanguageInterface

The language object.

int save()

Saves an entity permanently.

When saving existing entities, the entity is assumed to be complete, partial updates of entities are not supported.

Return Value

int

Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Exceptions

EntityStorageException

delete()

Deletes an entity permanently.

EntityInterface createDuplicate()

Creates a duplicate of the entity.

Return Value

EntityInterface

A clone of $this with all identifiers unset, so saving it inserts a new entity into the storage system.

abstract ContentEntityTypeInterface getEntityType()

Gets the entity type definition.

Return Value

ContentEntityTypeInterface

The content entity type definition.

preSave(EntityStorageInterface $storage)

Acts on an entity before the presave hook is invoked.

Used before the entity is saved and before invoking the presave hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed. This is different from its counterpart in the Field API, FieldItemListInterface::preSave(), which is fired on all field translations automatically.

Parameters

EntityStorageInterface $storage

The entity storage object.

Exceptions

Exception

postSave(EntityStorageInterface $storage, bool $update = TRUE)

Acts on a saved entity before the insert or update hook is invoked.

Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.

Parameters

EntityStorageInterface $storage

The entity storage object.

bool $update

TRUE if the entity has been updated, or FALSE if it has been inserted.

static preCreate(EntityStorageInterface $storage, array $values)

Changes the values of an entity before it is created.

Load defaults for example.

Parameters

EntityStorageInterface $storage

The entity storage object.

array $values

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

postCreate(EntityStorageInterface $storage)

Acts on a created entity before hooks are invoked.

Used after the entity is created, but before saving the entity and before any of the presave hooks are invoked.

See the @link entity_crud Entity CRUD topic @endlink for more information.

Parameters

EntityStorageInterface $storage

The entity storage object.

static preDelete(EntityStorageInterface $storage, array $entities)

Acts on entities before they are deleted and before hooks are invoked.

Used before the entities are deleted and before invoking the delete hook.

Parameters

EntityStorageInterface $storage

The entity storage object.

array $entities

An array of entities.

static postDelete(EntityStorageInterface $storage, array $entities)

Acts on deleted entities before the delete hook is invoked.

Used after the entities are deleted but before invoking the delete hook.

Parameters

EntityStorageInterface $storage

The entity storage object.

array $entities

An array of entities.

static postLoad(EntityStorageInterface $storage, array $entities)

Acts on loaded entities.

Parameters

EntityStorageInterface $storage

The entity storage object.

array $entities

An array of entities.

EntityInterface[] referencedEntities()

Gets a list of entities referenced by this entity.

Return Value

EntityInterface[]

An array of entities.

protected string[] getListCacheTagsToInvalidate()

The list cache tags to invalidate for this entity.

Return Value

string[]

Set of list cache tags.

string[] getCacheTagsToInvalidate()

Returns the cache tags that should be used to invalidate caches.

This will not return additional cache tags added through addCacheTags().

Return Value

string[]

Set of cache tags.

static EntityInterface|null load(mixed $id)

Loads an entity.

Parameters

mixed $id

The id of the entity to load.

Return Value

EntityInterface|null

The entity object or NULL if there is no entity with the given ID.

static 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.

static 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

The entity object.

protected invalidateTagsOnSave(bool $update)

Invalidates an entity's cache tags upon save.

Parameters

bool $update

TRUE if the entity has been updated, or FALSE if it has been inserted.

static protected invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities)

Invalidates an entity's cache tags upon delete.

Parameters

EntityTypeInterface $entity_type

The entity type definition.

array $entities

An array of entities.

int|string|null getOriginalId()

Gets the original ID.

Return Value

int|string|null

The original ID, or NULL if no ID was set or for entity types that do not support renames.

$this setOriginalId(int|string|null $id)

Sets the original ID.

Parameters

int|string|null $id

The new ID to set as original ID. If the entity supports renames, setting NULL will prevent an update from being considered a rename.

Return Value

$this

array toArray()

Gets an array of all property values.

Return Value

array

An array of property values, keyed by property name.

ComplexDataInterface getTypedData()

Gets a typed data object for this entity object.

The returned typed data object wraps this entity and allows dealing with entities based on the generic typed data API.

Return Value

ComplexDataInterface

The typed data object for this entity.

string getConfigDependencyKey()

Gets the key that is used to store configuration dependencies.

Return Value

string

The key to be used in configuration dependencies when storing dependencies on entities of this type.

string getConfigDependencyName()

Gets the configuration dependency name.

Configuration entities can depend on content and configuration entities. They store an array of content and config dependency names in their "dependencies" key.

Return Value

string

The configuration dependency name.

string getConfigTarget()

Gets the configuration target identifier for the entity.

Used to supply the correct format for storing a reference targeting this entity in configuration.

Return Value

string

The configuration target identifier.

protected string[] getFieldsToSkipFromTranslationChangesCheck(ContentEntityInterface $entity)

Returns an array of field names to skip when checking for changes.

Parameters

ContentEntityInterface $entity

A content entity object.

Return Value

string[]

An array of field names.

setSyncing($syncing)

{@inheritdoc}

Parameters

$syncing

isSyncing()

{@inheritdoc}

protected getLanguages()

{@inheritdoc}

setNewRevision(bool $value = TRUE)

Enforces an entity to be saved as a new revision.

Parameters

bool $value

(optional) Whether a new revision should be saved.

Exceptions

LogicException

int getLoadedRevisionId()

Gets the loaded Revision ID of the entity.

Return Value

int

The loaded Revision identifier of the entity, or NULL if the entity does not have a revision identifier.

$this updateLoadedRevisionId()

Updates the loaded Revision ID with the revision ID.

This method should not be used, it could unintentionally cause the original revision ID property value to be lost.

Return Value

$this

bool isNewRevision()

Determines whether a new revision should be created on save.

Return Value

bool

TRUE if a new revision should be created.

bool isDefaultRevision(bool $new_value = NULL)

Checks if this entity is the default revision.

Parameters

bool $new_value

(optional) A Boolean to (re)set the isDefaultRevision flag.

Return Value

bool

TRUE if the entity is the default revision, FALSE otherwise. If $new_value was passed, the previous value is returned.

bool wasDefaultRevision()

Checks whether the entity object was a default revision when it was saved.

Return Value

bool

TRUE if the entity object was a revision, FALSE otherwise.

bool isLatestRevision()

Checks if this entity is the latest revision.

Return Value

bool

TRUE if the entity is the latest revision, FALSE otherwise.

bool isLatestTranslationAffectedRevision()

Checks whether this is the latest revision affecting this translation.

Return Value

bool

TRUE if this revision is the latest one affecting the active translation, FALSE otherwise.

bool isRevisionTranslationAffected()

Checks whether the current translation is affected by the current revision.

Return Value

bool

TRUE if the entity object is affected by the current revision, FALSE otherwise.

$this setRevisionTranslationAffected(bool|null $affected)

Marks the current revision translation as affected.

Setting the revision translation affected flag through the setter or through the field directly will always enforce it, which will be used by the entity storage to determine if the flag should be recomputed or the set value should be used instead.

Parameters

bool|null $affected

The flag value. A NULL value can be specified to reset the current value and make sure a new value will be computed by the system.

Return Value

$this

bool isRevisionTranslationAffectedEnforced()

Checks if the revision translation affected flag value has been enforced.

Return Value

bool

TRUE if revision translation affected flag is enforced, FALSE otherwise.

$this setRevisionTranslationAffectedEnforced(bool $enforced)

Enforces the revision translation affected flag value.

Note that this method call will not have any influence on the storage if the value of the revision translation affected flag is NULL which is used as an indication for the storage to recompute the flag.

Parameters

bool $enforced

If TRUE, the value of the revision translation affected flag will be enforced so that on entity save the entity storage will not recompute it. Otherwise the storage will recompute it.

Return Value

$this

bool isDefaultTranslation()

Checks whether the translation is the default one.

Return Value

bool

TRUE if the translation is the default one, FALSE otherwise.

The getRevisionId()

Gets the revision identifier of the entity.

Return Value

The

revision identifier of the entity, or NULL if the entity does not have a revision identifier.

bool isTranslatable()

Returns the translation support status.

Return Value

bool

TRUE if the object has translation support enabled.

preSaveRevision(EntityStorageInterface $storage, stdClass $record)

Acts on a revision before it gets saved.

Parameters

EntityStorageInterface $storage

The entity storage object.

stdClass $record

The revision object.

EntityConstraintViolationListInterface validate()

Validates the currently set values.

Return Value

EntityConstraintViolationListInterface

A list of constraint violations. If the list is empty, validation succeeded.

bool isValidationRequired()

Checks whether entity validation is required before saving the entity.

Return Value

bool

TRUE if validation is required, FALSE if not.

$this setValidationRequired(bool $required)

Sets whether entity validation is required before saving the entity.

Parameters

bool $required

TRUE if validation is required, FALSE otherwise.

Return Value

$this

protected clearTranslationCache()

Clear entity translation object cache to remove stale references.

bool hasField(string $field_name)

Determines whether the entity has a field with the given name.

Parameters

string $field_name

The field name.

Return Value

bool

TRUE if the entity has a field with the given name. FALSE otherwise.

FieldItemListInterface get(string $field_name)

Gets a field item list.

Parameters

string $field_name

The name of the field to get; e.g., 'title' or 'name'.

Return Value

FieldItemListInterface

The field item list, containing the field items.

Exceptions

InvalidArgumentException

protected FieldItemListInterface getTranslatedField($name, $langcode)

Gets a translated field.

Parameters

$name
$langcode

Return Value

FieldItemListInterface

$this set($name, mixed $value, bool $notify = TRUE)

Sets a field value.

Parameters

$name
mixed $value

The value to set, or NULL to unset the field.

bool $notify

(optional) Whether to notify the entity of the change. Defaults to TRUE. If the update stems from the entity, set it to FALSE to avoid being notified again.

Return Value

$this

Exceptions

InvalidArgumentException

FieldItemListInterface[] getFields(bool $include_computed = TRUE)

Gets an array of all field item lists.

Parameters

bool $include_computed

If set to TRUE, computed fields are included. Defaults to TRUE.

Return Value

FieldItemListInterface[]

An array of field item lists implementing, keyed by field name.

FieldItemListInterface[] getTranslatableFields(bool $include_computed = TRUE)

Gets an array of field item lists for translatable fields.

Parameters

bool $include_computed

If set to TRUE, computed fields are included. Defaults to TRUE.

Return Value

FieldItemListInterface[]

An array of field item lists implementing, keyed by field name.

getIterator()

{@inheritdoc}

FieldDefinitionInterface|null getFieldDefinition(string $name)

Gets the definition of a contained field.

Parameters

string $name

The name of the field.

Return Value

FieldDefinitionInterface|null

The definition of the field or null if the field does not exist.

FieldDefinitionInterface[] getFieldDefinitions()

Gets an array of field definitions of all contained fields.

Return Value

FieldDefinitionInterface[]

An array of field definitions, keyed by field name.

protected setDefaultLangcode()

Populates the local cache for the default language code.

protected updateFieldLangcodes($langcode)

Updates language for already instantiated fields.

Parameters

$langcode

onChange($name)

Reacts to changes to a field.

Note that this is invoked after any changes have been applied.

Parameters

$name

Exceptions

InvalidArgumentException
LogicException

$this getTranslation($langcode)

Gets a translation of the data.

The returned translation has to be of the same type than this typed data object.

Parameters

$langcode

The language code of the translation to get or LanguageInterface::LANGCODE_DEFAULT to get the data in default language.

Return Value

$this

A typed data object for the translated data.

Exceptions

InvalidArgumentException

$this getUntranslated()

Returns the translatable object referring to the original language.

Return Value

$this

The translation object referring to the original language.

protected EntityInterface initializeTranslation(string $langcode)

Instantiates a translation object for an existing translation.

The translated entity will be a clone of the current entity with the specified $langcode. All translations share the same field data structures to ensure that all of them deal with fresh data.

Parameters

string $langcode

The language code for the requested translation.

Return Value

EntityInterface

The translation object. The content properties of the translation object are stored as references to the main entity.

bool hasTranslation(string $langcode)

Checks there is a translation for the given language code.

Parameters

string $langcode

The language code identifying the translation.

Return Value

bool

TRUE if the translation exists, FALSE otherwise.

bool isNewTranslation()

Checks whether the translation is new.

Return Value

bool

TRUE if the translation is new, FALSE otherwise.

$this addTranslation(string $langcode, array $values = [])

Adds a new translation to the translatable object.

To create a translation of an entity prefilled with the original data:

Parameters

string $langcode

The language code identifying the translation.

array $values

(optional) An array of initial values to be assigned to the translatable fields. Defaults to none.

Return Value

$this

Exceptions

InvalidArgumentException

removeTranslation(string $langcode)

Removes the translation identified by the given language code.

Parameters

string $langcode

The language code identifying the translation to be removed.

int|null getTranslationStatus(string $langcode)

Returns the translation status.

Parameters

string $langcode

The language code identifying the translation.

Return Value

int|null

One of the TRANSLATION_* constants or NULL if the given translation does not exist.

LanguageInterface[] getTranslationLanguages(bool $include_default = TRUE)

Returns the languages the data is translated to.

Parameters

bool $include_default

(optional) Whether the default language should be included. Defaults to TRUE.

Return Value

LanguageInterface[]

An associative array of language objects, keyed by language codes.

updateOriginalValues()

Updates the original values with the interim changes.

__get($name)

Implements the magic method for getting object properties.

Parameters

$name

__set($name, $value)

Implements the magic method for setting object properties.

Uses default language always.

Parameters

$name
$value

__isset($name)

Implements the magic method for isset().

Parameters

$name

__unset($name)

Implements the magic method for unset().

Parameters

$name

__clone()

Magic method: Implements a deep clone.

protected mixed getEntityKey(string $key)

Gets the value of the given entity key, if defined.

Parameters

string $key

Name of the entity key, for example id, revision or bundle.

Return Value

mixed

The value of the entity key, NULL if not defined.

static FieldDefinitionInterface[] baseFieldDefinitions(EntityTypeInterface $entity_type)

Provides base field definitions for an entity type.

Implementations typically use the class \Drupal\Core\Field\BaseFieldDefinition for creating the field definitions; for example a 'name' field could be defined as the following:

Parameters

EntityTypeInterface $entity_type

The entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.

Return Value

FieldDefinitionInterface[]

An array of base field definitions for the entity type, keyed by field name.

static FieldDefinitionInterface[] bundleFieldDefinitions(EntityTypeInterface $entity_type, string $bundle, array $base_field_definitions)

Provides field definitions for a specific bundle.

This function can return definitions both for bundle fields (fields that are not defined in $base_field_definitions, and therefore might not exist on some bundles) as well as bundle-specific overrides of base fields (fields that are defined in $base_field_definitions, and therefore exist for all bundles). However, bundle-specific base field overrides can also be provided by 'base_field_override' configuration entities, and that is the recommended approach except in cases where an entity type needs to provide a bundle-specific base field override that is decoupled from configuration. Note that for most entity types, the bundles themselves are derived from configuration (e.g., 'node' bundles are managed via 'node_type' configuration entities), so decoupling bundle-specific base field overrides from configuration only makes sense for entity types that also decouple their bundles from configuration. In cases where both this function returns a bundle-specific override of a base field and a 'base_field_override' configuration entity exists, the latter takes precedence.

Parameters

EntityTypeInterface $entity_type

The entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.

string $bundle

The bundle.

array $base_field_definitions

The list of base field definitions.

Return Value

FieldDefinitionInterface[]

An array of bundle field definitions, keyed by field name.

bool hasTranslationChanges()

Determines if the current translation of the entity has unsaved changes.

Return Value

bool

TRUE if the current translation of the entity has changes.

bool isDefaultTranslationAffectedOnly()

Checks if untranslatable fields should affect only the default translation.

Return Value

bool

TRUE if untranslatable fields should affect only the default translation, FALSE otherwise.

int getChangedTimeAcrossTranslations()

Returns the timestamp of the last entity change across all translations.

Return Value

int

The timestamp of the last entity save operation across all translations.

int getChangedTime()

Gets the timestamp of the last entity change for the current translation.

Return Value

int

The timestamp of the last entity save operation.

$this setChangedTime(int $timestamp)

Sets the timestamp of the last entity change for the current translation.

Parameters

int $timestamp

The timestamp of the last entity save operation.

Return Value

$this

static BaseFieldDefinition[] publishedBaseFieldDefinitions(EntityTypeInterface $entity_type)

Returns an array of base field definitions for publishing status.

Parameters

EntityTypeInterface $entity_type

The entity type to add the publishing status field to.

Return Value

BaseFieldDefinition[]

An array of base field definitions.

Exceptions

UnsupportedEntityTypeDefinitionException

isPublished()

{@inheritdoc}

setPublished()

{@inheritdoc}

setUnpublished()

{@inheritdoc}

static FieldDefinitionInterface[] revisionLogBaseFieldDefinitions(EntityTypeInterface $entity_type)

Provides revision-related base field definitions for an entity type.

Parameters

EntityTypeInterface $entity_type

The entity type definition.

Return Value

FieldDefinitionInterface[]

An array of base field definitions for the entity type, keyed by field name.

See also

FieldableEntityInterface::baseFieldDefinitions

getRevisionCreationTime()

Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionCreationTime().

setRevisionCreationTime($timestamp)

Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionCreationTime().

Parameters

$timestamp

getRevisionUser()

Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionUser().

setRevisionUser(UserInterface $account)

Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionUser().

Parameters

UserInterface $account

getRevisionUserId()

Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionUserId().

setRevisionUserId($user_id)

Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionUserId().

Parameters

$user_id

getRevisionLogMessage()

Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionLogMessage().

setRevisionLogMessage($revision_log_message)

Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionLogMessage().

Parameters

$revision_log_message

static protected string getRevisionMetadataKey(EntityTypeInterface $entity_type, string $key)

Gets the name of a revision metadata field.

Parameters

EntityTypeInterface $entity_type

A content entity type definition.

string $key

The revision metadata key to get, must be one of 'revision_created', 'revision_user' or 'revision_log_message'.

Return Value

string

The name of the field for the specified $key.

string getDescription()

Gets the term description.

Return Value

string

The term description.

$this setDescription(string $description)

Sets the term description.

Parameters

string $description

The term description.

Return Value

$this

string getFormat()

Gets the text format name for the term description.

Return Value

string

The text format name.

$this setFormat(string $format)

Sets the text format name for the term description.

Parameters

string $format

The text format name.

Return Value

$this

string getName()

Gets the term name.

Return Value

string

The term name.

$this setName(string $name)

Sets the term name.

Parameters

string $name

The term name.

Return Value

$this

int getWeight()

Gets the term weight.

Return Value

int

The term weight.

$this setWeight(int $weight)

Sets the term weight.

Parameters

int $weight

The term weight.

Return Value

$this