diff --git a/core/modules/content_moderation/src/EntityTypeInfo.php b/core/modules/content_moderation/src/EntityTypeInfo.php index 19a1982c87..29ac68d4f8 100644 --- a/core/modules/content_moderation/src/EntityTypeInfo.php +++ b/core/modules/content_moderation/src/EntityTypeInfo.php @@ -299,9 +299,13 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id ->getHandler($entity->getEntityTypeId(), 'moderation') ->enforceRevisionsEntityFormAlter($form, $form_state, $form_id); - if ((!$entity->isRevisionTranslationAffected() || !$this->moderationInfo->isLatestRevision($entity)) && count($entity->getTranslationLanguages()) > 1 && $this->moderationInfo->hasForwardRevision($entity)) { + // 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)) { $latest_revision = $this->getTranslationAffectedRevision($this->moderationInfo->getLatestRevision($entity->getEntityTypeId(), $entity->id())); - drupal_set_message(\Drupal::translation()->translate('It is not possible to save this @entity_type_label, publish or delete the latest revision to allow all workflow transitions.', ['@entity_type_label' => $entity->getEntityType()->getLabel(), '@latest_revision_edit_url' => $latest_revision->toUrl('edit-form', ['language' => $latest_revision->language()])->toString(), '@latest_revision_delete_url' => $latest_revision->toUrl('delete-form', ['language' => $latest_revision->language()])->toString()]), 'error'); + drupal_set_message(\Drupal::translation()->translate('It is not possible to save this @entity_type_label, publish or delete the latest draft revision to allow all workflow transitions.', ['@entity_type_label' => $entity->getEntityType()->getLabel(), '@latest_revision_edit_url' => $latest_revision->toUrl('edit-form', ['language' => $latest_revision->language()])->toString(), '@latest_revision_delete_url' => $latest_revision->toUrl('delete-form', ['language' => $latest_revision->language()])->toString()]), 'error'); $form['actions']['#access'] = FALSE; $form['invalid_transitions'] = [ 'rule' => [ @@ -316,7 +320,7 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id ], 'message' => [ '#type' => 'item', - '#markup' => \Drupal::translation()->translate('Publish or delete the latest revision to allow all workflow transitions.', ['@latest_revision_edit_url' => $latest_revision->toUrl('edit-form', ['language' => $latest_revision->language()])->toString(), '@latest_revision_delete_url' => $latest_revision->toUrl('delete-form', ['language' => $latest_revision->language()])->toString()]), + '#markup' => \Drupal::translation()->translate('Publish or delete the latest draft revision to allow all workflow transitions.', ['@latest_revision_edit_url' => $latest_revision->toUrl('edit-form', ['language' => $latest_revision->language()])->toString(), '@latest_revision_delete_url' => $latest_revision->toUrl('delete-form', ['language' => $latest_revision->language()])->toString()]), ], '#weight' => 999, '#no_valid_transitions' => TRUE, diff --git a/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php b/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php index eac1913fca..786d45f23d 100644 --- a/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php +++ b/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php @@ -92,13 +92,12 @@ public function convert($value, $definition, $name, array $defaults) { $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); $latest_revision = $this->moderationInformation->getLatestRevision($entity_type_id, $value); - // If the entity type is translatable, ensure we return the proper - // translation object for the current context. - if ($latest_revision instanceof EntityInterface && $entity instanceof TranslatableInterface) { - $latest_revision = $this->entityManager->getTranslationFromContext($latest_revision, NULL, ['operation' => 'entity_upcast']); - } - - if ($latest_revision instanceof EntityInterface && $latest_revision->isRevisionTranslationAffected()) { + if ($latest_revision instanceof EntityInterface) { + // If the entity type is translatable, ensure we return the proper + // translation object for the current context. + if ($entity instanceof TranslatableInterface) { + $latest_revision = $this->entityManager->getTranslationFromContext($latest_revision, NULL, ['operation' => 'entity_upcast']); + } $entity = $latest_revision; } }