diff --git a/core/modules/content_moderation/src/EntityOperations.php b/core/modules/content_moderation/src/EntityOperations.php index 48fe678ed9..6cb2791807 100644 --- a/core/modules/content_moderation/src/EntityOperations.php +++ b/core/modules/content_moderation/src/EntityOperations.php @@ -241,7 +241,7 @@ public function entityView(array &$build, EntityInterface $entity, EntityViewDis // - The revision is not translation affected. // - There are more than one translation languages. // - The entity has forward revisions. - if (!$entity->isRevisionTranslationAffected() && count($entity->getTranslationLanguages()) > 1 && $this->moderationInfo->hasForwardRevision($entity)) { + if ($this->moderationInfo->isForwardRevisionAllowed($entity)) { return; } diff --git a/core/modules/content_moderation/src/EntityTypeInfo.php b/core/modules/content_moderation/src/EntityTypeInfo.php index ee154998d4..1757711361 100644 --- a/core/modules/content_moderation/src/EntityTypeInfo.php +++ b/core/modules/content_moderation/src/EntityTypeInfo.php @@ -300,11 +300,7 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id ->getHandler($entity->getEntityTypeId(), 'moderation') ->enforceRevisionsEntityFormAlter($form, $form_state, $form_id); - // Prevent saving and display error when: - // - The revision is not translation affected. - // - There are more than one translation languages. - // - The entity has forward revisions. - if (!$entity->isRevisionTranslationAffected() && count($entity->getTranslationLanguages()) > 1 && $this->moderationInfo->hasForwardRevision($entity)) { + if ($this->moderationInfo->isForwardRevisionAllowed($entity)) { $latest_revision = $this->moderationInfo->getLatestRevision($entity->getEntityTypeId(), $entity->id()); if ($entity->bundle()) { $bundle_type_id = $entity->getEntityType()->getBundleEntityType(); @@ -315,7 +311,7 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id $type_label = $entity->getEntityType()->getLabel(); } $label = $this->t('Unable to save this @type_label.', ['@type_label' => $type_label]); - $translation = $this->moderationInfo->getRevisionTranslationAffectedTranslation($latest_revision); + $translation = $this->moderationInfo->getAffectedRevisionTranslation($latest_revision); $message = $this->t('Publish or delete the latest draft revision to allow all workflow transitions.', ['@latest_revision_edit_url' => $translation->toUrl('edit-form', ['language' => $translation->language()])->toString(), '@latest_revision_delete_url' => $translation->toUrl('delete-form', ['language' => $translation->language()])->toString()]); drupal_set_message(Markup::create($label . ' ' . $message), 'error'); diff --git a/core/modules/content_moderation/src/ModerationInformation.php b/core/modules/content_moderation/src/ModerationInformation.php index f86e484987..09de88981d 100644 --- a/core/modules/content_moderation/src/ModerationInformation.php +++ b/core/modules/content_moderation/src/ModerationInformation.php @@ -115,10 +115,10 @@ public function getDefaultRevisionId($entity_type_id, $entity_id) { /** * {@inheritdoc} */ - public function getRevisionTranslationAffectedTranslation(ContentEntityInterface $entity) { + public function getAffectedRevisionTranslation(ContentEntityInterface $entity) { foreach ($entity->getTranslationLanguages() as $language) { $translation = $entity->getTranslation($language->getId()); - if ($translation->isRevisionTranslationAffected()) { + if (!$translation->isDefaultRevision() && $translation->isRevisionTranslationAffected()) { return $translation; } } @@ -127,6 +127,13 @@ public function getRevisionTranslationAffectedTranslation(ContentEntityInterface /** * {@inheritdoc} */ + public function isForwardRevisionAllowed(ContentEntityInterface $entity) { + return !(!$entity->isRevisionTranslationAffected() && count($entity->getTranslationLanguages()) > 1 && $this->hasForwardRevision($entity)); + } + + /** + * {@inheritdoc} + */ public function isLatestRevision(ContentEntityInterface $entity) { return $entity->getRevisionId() == $this->getLatestRevisionId($entity->getEntityTypeId(), $entity->id()); } diff --git a/core/modules/content_moderation/src/ModerationInformationInterface.php b/core/modules/content_moderation/src/ModerationInformationInterface.php index 53d4750309..92e338daa6 100644 --- a/core/modules/content_moderation/src/ModerationInformationInterface.php +++ b/core/modules/content_moderation/src/ModerationInformationInterface.php @@ -98,7 +98,18 @@ public function getDefaultRevisionId($entity_type_id, $entity_id); * @return \Drupal\Core\Entity\ContentEntityInterface * The revision translation affected translation. */ - public function getRevisionTranslationAffectedTranslation(ContentEntityInterface $entity); + public function getAffectedRevisionTranslation(ContentEntityInterface $entity); + + /** + * Determines if forward revisions are allowed. + * + * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * The content entity. + * + * @return bool + * If forward revisions are allowed. + */ + public function isForwardRevisionAllowed(ContentEntityInterface $entity); /** * Determines if an entity is a latest revision.