Same name in this branch
- 10 core/modules/content_moderation/src/ContentModerationState.php \Drupal\content_moderation\ContentModerationState
- 10 core/modules/content_moderation/src/Entity/ContentModerationState.php \Drupal\content_moderation\Entity\ContentModerationState
Same name and namespace in other branches
- 8.9.x core/modules/content_moderation/src/Entity/ContentModerationState.php \Drupal\content_moderation\Entity\ContentModerationState
- 9 core/modules/content_moderation/src/Entity/ContentModerationState.php \Drupal\content_moderation\Entity\ContentModerationState
Defines the Content moderation state entity.
@ContentEntityType( id = "content_moderation_state", label = @Translation("Content moderation state"), label_singular = @Translation("content moderation state"), label_plural = @Translation("content moderation states"), label_count = @PluralTranslation( singular = "@count content moderation state", plural = "@count content moderation states" ), handlers = { "storage_schema" = "Drupal\content_moderation\ContentModerationStateStorageSchema", "views_data" = "\Drupal\views\EntityViewsData", "access" = "Drupal\content_moderation\ContentModerationStateAccessControlHandler", }, base_table = "content_moderation_state", revision_table = "content_moderation_state_revision", data_table = "content_moderation_state_field_data", revision_data_table = "content_moderation_state_field_revision", translatable = TRUE, internal = TRUE, entity_keys = { "id" = "id", "revision" = "revision_id", "uuid" = "uuid", "uid" = "uid", "owner" = "uid", "langcode" = "langcode", } )
@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.
Hierarchy
- class \Drupal\content_moderation\Entity\ContentModerationState extends \Drupal\Core\Entity\ContentEntityBase implements ContentModerationStateInterface uses EntityOwnerTrait
Expanded class hierarchy of ContentModerationState
4 files declare their use of ContentModerationState
- ContentModerationResaveTest.php in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationResaveTest.php - ContentModerationStateAccessControlHandlerTest.php in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateAccessControlHandlerTest.php - ContentModerationStateStorageSchemaTest.php in core/
modules/ content_moderation/ tests/ src/ Kernel/ ContentModerationStateStorageSchemaTest.php - EntityOperations.php in core/
modules/ content_moderation/ src/ EntityOperations.php
File
- core/
modules/ content_moderation/ src/ Entity/ ContentModerationState.php, line 50
Namespace
Drupal\content_moderation\EntityView source
class ContentModerationState extends ContentEntityBase implements ContentModerationStateInterface {
use EntityOwnerTrait;
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields += static::ownerBaseFieldDefinitions($entity_type);
$fields['uid']
->setLabel(t('User'))
->setDescription(t('The username of the entity creator.'))
->setRevisionable(TRUE);
$fields['workflow'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Workflow'))
->setDescription(t('The workflow the moderation state is in.'))
->setSetting('target_type', 'workflow')
->setRequired(TRUE)
->setRevisionable(TRUE);
$fields['moderation_state'] = BaseFieldDefinition::create('string')
->setLabel(t('Moderation state'))
->setDescription(t('The moderation state of the referenced content.'))
->setRequired(TRUE)
->setTranslatable(TRUE)
->setRevisionable(TRUE);
$fields['content_entity_type_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Content entity type ID'))
->setDescription(t('The ID of the content entity type this moderation state is for.'))
->setRequired(TRUE)
->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH)
->setRevisionable(TRUE);
$fields['content_entity_id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Content entity ID'))
->setDescription(t('The ID of the content entity this moderation state is for.'))
->setRequired(TRUE)
->setRevisionable(TRUE);
$fields['content_entity_revision_id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Content entity revision ID'))
->setDescription(t('The revision ID of the content entity this moderation state is for.'))
->setRequired(TRUE)
->setRevisionable(TRUE);
return $fields;
}
/**
* Creates or updates an entity's moderation state whilst saving that entity.
*
* @param \Drupal\content_moderation\Entity\ContentModerationState $content_moderation_state
* The content moderation entity content entity to create or save.
*
* @internal
* This method should only be called as a result of saving the related
* content entity.
*/
public static function updateOrCreateFromEntity(ContentModerationState $content_moderation_state) {
$content_moderation_state
->realSave();
}
/**
* Loads a content moderation state entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* A moderated entity object.
*
* @return \Drupal\content_moderation\Entity\ContentModerationStateInterface|null
* The related content moderation state or NULL if none could be found.
*
* @internal
* This method should only be called by code directly handling the
* ContentModerationState entity objects.
*/
public static function loadFromModeratedEntity(EntityInterface $entity) {
$content_moderation_state = NULL;
$moderation_info = \Drupal::service('content_moderation.moderation_information');
if ($moderation_info
->isModeratedEntity($entity)) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$storage = \Drupal::entityTypeManager()
->getStorage('content_moderation_state');
// New entities may not have a loaded revision ID at this point, but the
// creation of a content moderation state entity may have already been
// triggered elsewhere. In this case we have to match on the revision ID
// (instead of the loaded revision ID).
$revision_id = $entity
->getLoadedRevisionId() ?: $entity
->getRevisionId();
$ids = $storage
->getQuery()
->accessCheck(FALSE)
->condition('content_entity_type_id', $entity
->getEntityTypeId())
->condition('content_entity_id', $entity
->id())
->condition('workflow', $moderation_info
->getWorkflowForEntity($entity)
->id())
->condition('content_entity_revision_id', $revision_id)
->allRevisions()
->execute();
if ($ids) {
/** @var \Drupal\content_moderation\Entity\ContentModerationStateInterface $content_moderation_state */
$content_moderation_state = $storage
->loadRevision(key($ids));
}
}
return $content_moderation_state;
}
/**
* {@inheritdoc}
*/
public function save() {
/** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
$storage = \Drupal::entityTypeManager()
->getStorage($this->content_entity_type_id->value);
$related_entity = $storage
->loadRevision($this->content_entity_revision_id->value);
if ($related_entity instanceof TranslatableInterface) {
$related_entity = $related_entity
->getTranslation($this->activeLangcode);
}
$related_entity->moderation_state = $this->moderation_state;
return $related_entity
->save();
}
/**
* Saves an entity permanently.
*
* When saving existing entities, the entity is assumed to be complete,
* partial updates of entities are not supported.
*
* @return int
* Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
*
* @throws \Drupal\Core\Entity\EntityStorageException
* In case of failures an exception is thrown.
*/
protected function realSave() {
return parent::save();
}
/**
* {@inheritdoc}
*/
protected function getFieldsToSkipFromTranslationChangesCheck() {
$field_names = parent::getFieldsToSkipFromTranslationChangesCheck();
// We need to skip the parent entity revision ID, since that will always
// change on every save, otherwise every translation would be marked as
// affected regardless of actual changes.
$field_names[] = 'content_entity_revision_id';
return $field_names;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccessibleInterface:: |
public | function | Checks data value access. | 6 |
CacheableDependencyInterface:: |
public | function | The cache contexts associated with this object. | 12 |
CacheableDependencyInterface:: |
public | function | The maximum age for which this object may be cached. | 12 |
CacheableDependencyInterface:: |
public | function | The cache tags associated with this object. | 12 |
ContentModerationState:: |
public static | function |
Provides base field definitions for an entity type. Overrides FieldableEntityInterface:: |
|
ContentModerationState:: |
protected | function | ||
ContentModerationState:: |
public static | function | Loads a content moderation state entity. | |
ContentModerationState:: |
protected | function | Saves an entity permanently. | |
ContentModerationState:: |
public | function |
Saves an entity permanently. Overrides EntityInterface:: |
|
ContentModerationState:: |
public static | function | Creates or updates an entity's moderation state whilst saving that entity. | |
EntityInterface:: |
public | function | Gets the bundle of the entity. | 1 |
EntityInterface:: |
public static | function | Constructs a new entity object, without permanently saving it. | 1 |
EntityInterface:: |
public | function | Creates a duplicate of the entity. | 2 |
EntityInterface:: |
public | function | Deletes an entity permanently. | 1 |
EntityInterface:: |
public | function | Enforces an entity to be new. | 1 |
EntityInterface:: |
public | function | Returns the cache tags that should be used to invalidate caches. | 3 |
EntityInterface:: |
public | function | Gets the key that is used to store configuration dependencies. | 1 |
EntityInterface:: |
public | function | Gets the configuration dependency name. | 1 |
EntityInterface:: |
public | function | Gets the configuration target identifier for the entity. | 1 |
EntityInterface:: |
public | function | Gets the entity type definition. | 1 |
EntityInterface:: |
public | function | Gets the ID of the type of the entity. | 1 |
EntityInterface:: |
public | function | Gets the original ID. | 1 |
EntityInterface:: |
public | function | Gets a typed data object for this entity object. | 1 |
EntityInterface:: |
public | function | Indicates if a link template exists for a given key. | 1 |
EntityInterface:: |
public | function | Gets the identifier. | 1 |
EntityInterface:: |
public | function | Determines whether the entity is new. | 1 |
EntityInterface:: |
public | function | Gets the label of the entity. | 3 |
EntityInterface:: |
public | function | Gets the language of the entity. | 1 |
EntityInterface:: |
public static | function | Loads an entity. | 1 |
EntityInterface:: |
public static | function | Loads one or more entities. | 1 |
EntityInterface:: |
public | function | Acts on a created entity before hooks are invoked. | 1 |
EntityInterface:: |
public static | function | Acts on deleted entities before the delete hook is invoked. | 7 |
EntityInterface:: |
public static | function | Acts on loaded entities. | 2 |
EntityInterface:: |
public | function | Acts on a saved entity before the insert or update hook is invoked. | 8 |
EntityInterface:: |
public static | function | Changes the values of an entity before it is created. | 4 |
EntityInterface:: |
public static | function | Acts on entities before they are deleted and before hooks are invoked. | 6 |
EntityInterface:: |
public | function | Acts on an entity before the presave hook is invoked. | 8 |
EntityInterface:: |
public | function | Gets a list of entities referenced by this entity. | 2 |
EntityInterface:: |
public | function | Sets the original ID. | 1 |
EntityInterface:: |
public | function | Generates the HTML for a link to this entity. | 1 |
EntityInterface:: |
public | function | Gets the URL object for the entity. | 1 |
EntityInterface:: |
public | function | Gets a list of URI relationships supported by this entity. | 1 |
EntityInterface:: |
public | function | Gets the entity UUID (Universally Unique Identifier). | 1 |
EntityOwnerTrait:: |
public static | function | Default value callback for 'owner' base field. | 1 |
EntityOwnerTrait:: |
public | function | 1 | |
EntityOwnerTrait:: |
public | function | ||
EntityOwnerTrait:: |
public static | function | Returns an array of base field definitions for entity owners. | |
EntityOwnerTrait:: |
public | function | ||
EntityOwnerTrait:: |
public | function | ||
FieldableEntityInterface:: |
public static | function | Provides field definitions for a specific bundle. | 2 |
FieldableEntityInterface:: |
public | function | Gets a field item list. | |
FieldableEntityInterface:: |
public | function | Gets the definition of a contained field. | |
FieldableEntityInterface:: |
public | function | Gets an array of field definitions of all contained fields. | |
FieldableEntityInterface:: |
public | function | Gets an array of all field item lists. | |
FieldableEntityInterface:: |
public | function | Gets an array of field item lists for translatable fields. | |
FieldableEntityInterface:: |
public | function | Determines whether the entity has a field with the given name. | |
FieldableEntityInterface:: |
public | function | Checks whether entity validation is required before saving the entity. | |
FieldableEntityInterface:: |
public | function | Reacts to changes to a field. | |
FieldableEntityInterface:: |
public | function | Sets a field value. | |
FieldableEntityInterface:: |
public | function | Sets whether entity validation is required before saving the entity. | |
FieldableEntityInterface:: |
public | function |
Gets an array of all field values. Overrides EntityInterface:: |
|
FieldableEntityInterface:: |
public | function | Validates the currently set values. | 1 |
RefinableCacheableDependencyInterface:: |
public | function | Adds a dependency on an object: merges its cacheability metadata. | |
RefinableCacheableDependencyInterface:: |
public | function | Adds cache contexts. | |
RefinableCacheableDependencyInterface:: |
public | function | Adds cache tags. | |
RefinableCacheableDependencyInterface:: |
public | function | Merges the maximum age (in seconds) with the existing maximum age. | |
RevisionableInterface:: |
public | function | Gets the loaded Revision ID of the entity. | |
RevisionableInterface:: |
public | function | Gets the revision identifier of the entity. | |
RevisionableInterface:: |
public | function | Checks if this entity is the default revision. | |
RevisionableInterface:: |
public | function | Checks if this entity is the latest revision. | |
RevisionableInterface:: |
public | function | Determines whether a new revision should be created on save. | |
RevisionableInterface:: |
public | function | Acts on a revision before it gets saved. | 3 |
RevisionableInterface:: |
public | function | Enforces an entity to be saved as a new revision. | |
RevisionableInterface:: |
public | function | Updates the loaded Revision ID with the revision ID. | |
RevisionableInterface:: |
public | function | Checks whether the entity object was a default revision when it was saved. | |
SynchronizableInterface:: |
public | function | Returns whether this entity is being changed as part of a synchronization. | |
SynchronizableInterface:: |
public | function | Sets the status of the synchronization flag. | |
TranslatableInterface:: |
public | function | Adds a new translation to the translatable object. | |
TranslatableInterface:: |
public | function | Gets a translation of the data. | |
TranslatableInterface:: |
public | function | Returns the languages the data is translated to. | |
TranslatableInterface:: |
public | function | Returns the translatable object in the language it was created. | |
TranslatableInterface:: |
public | function | Checks there is a translation for the given language code. | |
TranslatableInterface:: |
public | function | Determines if the current translation of the entity has unsaved changes. | |
TranslatableInterface:: |
public | function | Checks whether the translation is the default one. | |
TranslatableInterface:: |
public | function | Checks whether the translation is new. | |
TranslatableInterface:: |
public | function | Returns the translation support status. | |
TranslatableInterface:: |
public | function | Removes the translation identified by the given language code. | |
TranslatableRevisionableInterface:: |
public | function | Checks if untranslatable fields should affect only the default translation. | |
TranslatableRevisionableInterface:: |
public | function | Checks whether this is the latest revision affecting this translation. | |
TranslatableRevisionableInterface:: |
public | function | Checks whether the current translation is affected by the current revision. | |
TranslatableRevisionableInterface:: |
public | function | Checks if the revision translation affected flag value has been enforced. | |
TranslatableRevisionableInterface:: |
public | function | Marks the current revision translation as affected. | |
TranslatableRevisionableInterface:: |
public | function | Enforces the revision translation affected flag value. |