function ContentModerationState::loadFromModeratedEntity

Same name in other branches
  1. 9 core/modules/content_moderation/src/Entity/ContentModerationState.php \Drupal\content_moderation\Entity\ContentModerationState::loadFromModeratedEntity()
  2. 10 core/modules/content_moderation/src/Entity/ContentModerationState.php \Drupal\content_moderation\Entity\ContentModerationState::loadFromModeratedEntity()
  3. 11.x core/modules/content_moderation/src/Entity/ContentModerationState.php \Drupal\content_moderation\Entity\ContentModerationState::loadFromModeratedEntity()

Loads a content moderation state entity.

@internal This method should only be called by code directly handling the ContentModerationState entity objects.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: A moderated entity object.

Return value

\Drupal\content_moderation\Entity\ContentModerationStateInterface|null The related content moderation state or NULL if none could be found.

11 calls to ContentModerationState::loadFromModeratedEntity()
ContentModerationStateTest::testChangingContentLangcode in core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php
Test changing the language of content without adding a translation.
ContentModerationStateTest::testContentModerationStateDataRemoval in core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php
Tests removal of content moderation state entity.
ContentModerationStateTest::testContentModerationStatePendingRevisionDataRemoval in core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php
Tests removal of content moderation state pending entity revisions.
ContentModerationStateTest::testContentModerationStateRevisionDataRemoval in core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php
Tests removal of content moderation state entity revisions.
ContentModerationStateTest::testContentModerationStateTranslationDataRemoval in core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php
Tests removal of content moderation state translations.

... See full list

File

core/modules/content_moderation/src/Entity/ContentModerationState.php, line 129

Class

ContentModerationState
Defines the Content moderation state entity.

Namespace

Drupal\content_moderation\Entity

Code

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');
        $ids = $storage->getQuery()
            ->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', $entity->getLoadedRevisionId())
            ->allRevisions()
            ->execute();
        if ($ids) {
            
            /** @var \Drupal\content_moderation\Entity\ContentModerationStateInterface $content_moderation_state */
            $content_moderation_state = $storage->loadRevision(key($ids));
        }
    }
    return $content_moderation_state;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.