diff --git a/core/modules/content_moderation/src/EntityTypeInfo.php b/core/modules/content_moderation/src/EntityTypeInfo.php index 3620c0abcd..dfa5503ab9 100644 --- a/core/modules/content_moderation/src/EntityTypeInfo.php +++ b/core/modules/content_moderation/src/EntityTypeInfo.php @@ -301,10 +301,10 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id ->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)) { + // - The entity is not the latest revision; + if (count($entity->getTranslationLanguages()) > 1 && $this->moderationInfo->hasForwardRevision($entity) && !$this->moderationInfo->isLatestRevision($entity)) { $latest_revision = $this->moderationInfo->getLatestRevision($entity->getEntityTypeId(), $entity->id()); if ($entity->bundle()) { $bundle_type_id = $entity->getEntityType()->getBundleEntityType(); diff --git a/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php b/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php index 786d45f23d..c7a5419256 100644 --- a/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php +++ b/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php @@ -88,17 +88,31 @@ protected function isEditFormPage(Route $route) { public function convert($value, $definition, $name, array $defaults) { $entity = parent::convert($value, $definition, $name, $defaults); - if ($entity && $this->moderationInformation->isModeratedEntity($entity) && !$this->moderationInformation->isLatestRevision($entity)) { - $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); - $latest_revision = $this->moderationInformation->getLatestRevision($entity_type_id, $value); + if ($entity && $this->moderationInformation->isModeratedEntity($entity)) { + if (!$this->moderationInformation->isLatestRevision($entity)) { + $entity = $this->moderationInformation->getLatestRevision($entity->getEntityTypeId(), $value); + } - if ($latest_revision instanceof EntityInterface) { + if ($entity 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 = $this->entityManager->getTranslationFromContext($entity, NULL, ['operation' => 'entity_upcast']); + } + + if (!$entity->isRevisionTranslationAffected()) { + $id_key = $entity->getEntityType()->getKey('id'); + $revision_key = $entity->getEntityType()->getKey('revision'); + $storage = $this->entityManager->getStorage($entity->getEntityTypeId()); + $latest_revision_translation_affected_revision = $storage->getQuery() + ->allRevisions() + ->condition($id_key, $entity->id()) + ->condition('revision_translation_affected', 1) + ->range(1, 1) + ->sort($revision_key, 'ASC') + ->execute(); + $entity = $storage->loadRevision(key($latest_revision_translation_affected_revision)); } - $entity = $latest_revision; } } diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php index 986ef3a4e5..08d971ab36 100644 --- a/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php @@ -280,7 +280,7 @@ public function testContentTranslationNodeForm() { $this->assertFalse($this->xpath('//input[@value="Save and Create New Draft (this translation)"]')); $this->assertFalse($this->xpath('//input[@value="Save and Publish (this translation)"]')); $this->assertFalse($this->xpath('//input[@value="Save and Archive (this translation)"]')); - $this->assertText('It is not possible to save this Content.'); + $this->assertSession()->pageTextContains('Unable to save this Moderated content.'); // Publish the french forward revision (revision 4). $this->drupalGet('fr/' . $edit_path); @@ -288,7 +288,7 @@ public function testContentTranslationNodeForm() { $this->assertTrue($this->xpath('//input[@value="Save and Publish (this translation)"]')); $this->assertFalse($this->xpath('//input[@value="Save and Archive (this translation)"]')); $this->drupalPostForm(NULL, [ - 'body[0][value]' => 'Fifth version of the content.', + 'body[0][value]' => 'Forth version of the content.', ], t('Save and Publish (this translation)')); // Now we can publish the english (revision 5). @@ -297,7 +297,7 @@ public function testContentTranslationNodeForm() { $this->assertTrue($this->xpath('//input[@value="Save and Publish (this translation)"]')); $this->assertFalse($this->xpath('//input[@value="Save and Archive (this translation)"]')); $this->drupalPostForm(NULL, [ - 'body[0][value]' => 'Sixth version of the content.', + 'body[0][value]' => 'Fifth version of the content.', ], t('Save and Publish (this translation)')); // Make sure we're allowed to create a forward french revision. @@ -312,7 +312,7 @@ public function testContentTranslationNodeForm() { $this->assertTrue($this->xpath('//input[@value="Save and Publish (this translation)"]')); $this->assertTrue($this->xpath('//input[@value="Save and Archive (this translation)"]')); $this->drupalPostForm(NULL, [ - 'body[0][value]' => 'Seventh version of the content.', + 'body[0][value]' => 'Sixth version of the content.', ], t('Save and Create New Draft (this translation)')); // Make sure we're not allowed to create a forward french revision. @@ -320,7 +320,7 @@ public function testContentTranslationNodeForm() { $this->assertFalse($this->xpath('//input[@value="Save and Create New Draft (this translation)"]')); $this->assertFalse($this->xpath('//input[@value="Save and Publish (this translation)"]')); $this->assertFalse($this->xpath('//input[@value="Save and Archive (this translation)"]')); - $this->assertText('It is not possible to save this Content.'); + $this->assertSession()->pageTextContains('Unable to save this Moderated content.'); // We should be able to publish the english forward revision (revision 7) $this->drupalGet($edit_path); @@ -328,7 +328,7 @@ public function testContentTranslationNodeForm() { $this->assertTrue($this->xpath('//input[@value="Save and Publish (this translation)"]')); $this->assertFalse($this->xpath('//input[@value="Save and Archive (this translation)"]')); $this->drupalPostForm(NULL, [ - 'body[0][value]' => 'Eighth version of the content.', + 'body[0][value]' => 'Seventh version of the content.', ], t('Save and Publish (this translation)')); // Make sure we're allowed to create a forward french revision.