function ModerationInformation::getOriginalState

Same name in other branches
  1. 9 core/modules/content_moderation/src/ModerationInformation.php \Drupal\content_moderation\ModerationInformation::getOriginalState()
  2. 8.9.x core/modules/content_moderation/src/ModerationInformation.php \Drupal\content_moderation\ModerationInformation::getOriginalState()
  3. 10 core/modules/content_moderation/src/ModerationInformation.php \Drupal\content_moderation\ModerationInformation::getOriginalState()

File

core/modules/content_moderation/src/ModerationInformation.php, line 214

Class

ModerationInformation
General service for moderation-related questions about Entity API.

Namespace

Drupal\content_moderation

Code

public function getOriginalState(ContentEntityInterface $entity) {
    $state = NULL;
    $workflow_type = $this->getWorkflowForEntity($entity)
        ->getTypePlugin();
    if (!$entity->isNew() && !$this->isFirstTimeModeration($entity)) {
        
        /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
        $storage = $this->entityTypeManager
            ->getStorage($entity->getEntityTypeId());
        
        /** @var \Drupal\Core\Entity\ContentEntityInterface $original_entity */
        $original_entity = $storage->loadRevision($entity->getLoadedRevisionId());
        if (!$entity->isDefaultTranslation() && $original_entity->hasTranslation($entity->language()
            ->getId())) {
            $original_entity = $original_entity->getTranslation($entity->language()
                ->getId());
        }
        if ($workflow_type->hasState($original_entity->moderation_state->value)) {
            $state = $workflow_type->getState($original_entity->moderation_state->value);
        }
    }
    return $state ?: $workflow_type->getInitialState($entity);
}

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