public function ModerationInformation::getOriginalState in Drupal 8
Same name and namespace in other branches
- 9 core/modules/content_moderation/src/ModerationInformation.php \Drupal\content_moderation\ModerationInformation::getOriginalState()
Gets the original or initial state of the given entity.
When a state is being validated, the original state is used to validate that a valid transition exists for target state and the user has access to the transition between those two states. If the entity has been moderated before, we can load the original unmodified revision and translation for this state.
If the entity is new we need to load the initial state from the workflow. Even if a value was assigned to the moderation_state field, the initial state is used to compute an appropriate transition for the purposes of validation.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The content entity to get the workflow for.
Return value
\Drupal\content_moderation\ContentModerationState The original or default moderation state.
Overrides ModerationInformationInterface::getOriginalState
File
- core/
modules/ content_moderation/ src/ ModerationInformation.php, line 241
Class
- ModerationInformation
- General service for moderation-related questions about Entity API.
Namespace
Drupal\content_moderationCode
public function getOriginalState(ContentEntityInterface $entity) {
$state = NULL;
$workflow_type = $this
->getWorkflowForEntity($entity)
->getTypePlugin();
if (!$entity
->isNew() && !$this
->isFirstTimeModeration($entity)) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $original_entity */
$original_entity = $this->entityTypeManager
->getStorage($entity
->getEntityTypeId())
->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);
}