You are here

public static function ContentModerationState::loadFromModeratedEntity in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/src/Entity/ContentModerationState.php \Drupal\content_moderation\Entity\ContentModerationState::loadFromModeratedEntity()
  2. 9 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.

4 calls to ContentModerationState::loadFromModeratedEntity()
EntityOperations::entityDelete in core/modules/content_moderation/src/EntityOperations.php
EntityOperations::entityRevisionDelete in core/modules/content_moderation/src/EntityOperations.php
EntityOperations::entityTranslationDelete in core/modules/content_moderation/src/EntityOperations.php
EntityOperations::updateOrCreateFromEntity in core/modules/content_moderation/src/EntityOperations.php
Creates or updates the moderation state of an entity.

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()
      ->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', $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;
}