ContentModerationState
class ContentModerationState extends ContentEntityBase implements ContentModerationStateInterface (View source)
| internal | This entity is marked internal because it should not be used directly to alter the moderation state of an entity. Instead, the computed moderation_state field should be set on the entity directly. |
Defines the Content moderation state entity.
Traits
Provides a trait for entities that have an owner.
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
Sets cacheability; useful for value object constructors.
Constructs an Entity object.
Gets the entity type bundle info service.
Gets the URL object for the entity.
Generates the HTML for a link to this entity.
Gets an array of placeholders for this entity.
Gets a list of URI relationships supported by this entity.
Checks data value access.
Saves an entity permanently.
Acts on a saved entity before the insert or update hook is invoked.
Changes the values of an entity before it is created.
Acts on entities before they are deleted and before hooks are invoked.
Acts on deleted entities before the delete hook is invoked.
Gets a list of entities referenced by this entity.
The list cache tags to invalidate for this entity.
Returns the cache tags that should be used to invalidate caches.
Loads one or more entities.
Constructs a new entity object, without permanently saving it.
Invalidates an entity's cache tags upon delete.
Gets a typed data object for this entity object.
Gets the key that is used to store configuration dependencies.
Returns an array of field names to skip in ::hasTranslationChanges.
Enforces an entity to be saved as a new revision.
Updates the loaded Revision ID with the revision ID.
Determines whether a new revision should be created on save.
Checks if this entity is the default revision.
Checks whether the entity object was a default revision when it was saved.
Checks whether this is the latest revision affecting this translation.
Checks whether the current translation is affected by the current revision.
Marks the current revision translation as affected.
Checks if the revision translation affected flag value has been enforced.
Enforces the revision translation affected flag value.
Checks whether the translation is the default one.
Acts on a revision before it gets saved.
Validates the currently set values.
Checks whether entity validation is required before saving the entity.
Sets whether entity validation is required before saving the entity.
Clear entity translation object cache to remove stale references.
Determines whether the entity has a field with the given name.
Gets a translated field.
Gets an array of all field item lists.
Gets an array of field item lists for translatable fields.
Gets the definition of a contained field.
Gets an array of field definitions of all contained fields.
Populates the local cache for the default language code.
Updates language for already instantiated fields.
Returns the translatable object referring to the original language.
Instantiates a translation object for an existing translation.
Checks there is a translation for the given language code.
Adds a new translation to the translatable object.
Removes the translation identified by the given language code.
Returns the translation status.
Returns the languages the data is translated to.
Implements the magic method for setting object properties.
Gets the value of the given entity key, if defined.
Provides base field definitions for an entity type.
Provides field definitions for a specific bundle.
Determines if the current translation of the entity has unsaved changes.
Checks if untranslatable fields should affect only the default translation.
Returns an array of base field definitions for entity owners.
Default value callback for 'owner' base field.
Creates or updates an entity's moderation state whilst saving that entity.
Saves an entity permanently.
Details
protected $this
setCacheability(CacheableDependencyInterface $cacheability)
Sets cacheability; useful for value object constructors.
getCacheTags()
{@inheritdoc}
getCacheContexts()
{@inheritdoc}
getCacheMaxAge()
{@inheritdoc}
addCacheableDependency($other_object)
{@inheritdoc}
addCacheContexts(array $cache_contexts)
{@inheritdoc}
addCacheTags(array $cache_tags)
{@inheritdoc}
mergeCacheMaxAge($max_age)
{@inheritdoc}
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
__construct(array $values, string $entity_type, $bundle = FALSE, $translations = [])
Constructs an Entity object.
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.
string|int|null
id()
Gets the 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.
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.
$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.
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.
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:
bool
hasLinkTemplate($rel)
Indicates if a link template exists for a given key.
protected array
linkTemplates()
Gets an array link templates.
Link
toLink(string|null $text = NULL, string $rel = 'canonical', array $options = [])
Generates the HTML for a link to this entity.
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.
string[]
uriRelationships()
Gets a list of URI relationships supported by this entity.
bool|AccessResultInterface
access(string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)
Checks data value access.
LanguageInterface
language()
Gets the language of the entity.
int
save()
Saves an entity permanently.
When saving existing entities, the entity is assumed to be complete, partial updates of entities are not supported.
delete()
Deletes an entity permanently.
EntityInterface
createDuplicate()
Creates a duplicate of the entity.
EntityTypeInterface
getEntityType()
Gets the 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.
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.
static
preCreate(EntityStorageInterface $storage, array $values)
Changes the values of an entity before it is created.
Load defaults for example.
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.
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.
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.
static
postLoad(EntityStorageInterface $storage, array $entities)
Acts on loaded entities.
EntityInterface[]
referencedEntities()
Gets a list of entities referenced by this entity.
protected string[]
getListCacheTagsToInvalidate()
The list cache tags to invalidate for this entity.
string[]
getCacheTagsToInvalidate()
Returns the cache tags that should be used to invalidate caches.
This will not return additional cache tags added through addCacheTags().
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.
protected
invalidateTagsOnSave(bool $update)
Invalidates an entity's cache tags upon save.
static protected
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.
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.
string
getConfigDependencyKey()
Gets the key that is used to store configuration dependencies.
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.
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.
protected array
getFieldsToSkipFromTranslationChangesCheck()
Returns an array of field names to skip in ::hasTranslationChanges.
setSyncing($syncing)
{@inheritdoc}
isSyncing()
{@inheritdoc}
protected
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.
This method should not be used, it could unintentionally cause the original revision ID property value to be lost.
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.
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.
bool
isRevisionTranslationAffectedEnforced()
Checks if the revision translation affected flag value has been enforced.
$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.
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.
EntityConstraintViolationListInterface
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.
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.
FieldItemListInterface
get(string $field_name)
Gets a field item list.
protected FieldItemListInterface
getTranslatedField($name, $langcode)
Gets a translated field.
$this
set($name, mixed $value, bool $notify = TRUE)
Sets a field value.
FieldItemListInterface[]
getFields(bool $include_computed = TRUE)
Gets an array of all field item lists.
FieldItemListInterface[]
getTranslatableFields(bool $include_computed = TRUE)
Gets an array of field item lists for translatable fields.
getIterator()
{@inheritdoc}
FieldDefinitionInterface|null
getFieldDefinition(string $name)
Gets the definition of a contained field.
FieldDefinitionInterface[]
getFieldDefinitions()
Gets an array of field definitions of all contained fields.
protected
setDefaultLangcode()
Populates the local cache for the default language code.
protected
updateFieldLangcodes($langcode)
Updates language for already instantiated fields.
onChange($name)
Reacts to changes to a field.
Note that this is invoked after any changes have been applied.
$this
getTranslation($langcode)
Gets a translation of the data.
The returned translation has to be of the same type than this typed data object.
$this
getUntranslated()
Returns the translatable 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.
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.
To create a translation of an entity prefilled with the original data:
removeTranslation(string $langcode)
Removes the translation identified by the given language code.
int|null
getTranslationStatus(string $langcode)
Returns the translation status.
LanguageInterface[]
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.
Uses default language always.
__isset($name)
Implements the magic method for isset().
__unset($name)
Implements the magic method for unset().
__clone()
Magic method: Implements a deep clone.
protected mixed
getEntityKey(string $key)
Gets the value of the given entity key, if 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:
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.
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.
static BaseFieldDefinition[]
ownerBaseFieldDefinitions(EntityTypeInterface $entity_type)
Returns an array of base field definitions for entity owners.
getOwnerId()
{@inheritdoc}
setOwnerId($uid)
{@inheritdoc}
getOwner()
{@inheritdoc}
setOwner(UserInterface $account)
{@inheritdoc}
static mixed
getDefaultEntityOwner()
Default value callback for 'owner' base field.
static
updateOrCreateFromEntity(ContentModerationState $content_moderation_state)
| internal | This method should only be called as a result of saving the related content entity. |
Creates or updates an entity's moderation state whilst saving that entity.
static ContentModerationStateInterface|null
loadFromModeratedEntity(EntityInterface $entity)
| internal | This method should only be called by code directly handling the ContentModerationState entity objects. |
Loads a content moderation state entity.
protected int
realSave()
Saves an entity permanently.
When saving existing entities, the entity is assumed to be complete, partial updates of entities are not supported.