diff --git a/core/modules/content_moderation/src/StateTransitionValidation.php b/core/modules/content_moderation/src/StateTransitionValidation.php index e8e2a4c..69f717d 100644 --- a/core/modules/content_moderation/src/StateTransitionValidation.php +++ b/core/modules/content_moderation/src/StateTransitionValidation.php @@ -53,9 +53,17 @@ public function getValidTransitions(ContentEntityInterface $entity, AccountInter // want to only allow specific transitions. if (count($entity->getTranslationLanguages()) > 1 && $this->moderationInfo->hasForwardRevision($entity)) { // The entity needs to be the latest and translation affected, or be - // going from and to the same default state. - return ($this->moderationInfo->isLatestRevision($entity) && $entity->isRevisionTranslationAffected()) - || (($entity->isDefaultRevision() && $transition->to()->isDefaultRevisionState()) || (!$entity->isDefaultRevision() && !$transition->to()->isDefaultRevisionState())); + // going from and to the same default revision state, or be going from + // and to the same publishing state. + return ( + $this->moderationInfo->isLatestRevision($entity) && $entity->isRevisionTranslationAffected() + ) || (( + ($entity->isDefaultRevision() && $transition->to()->isDefaultRevisionState()) + || (!$entity->isDefaultRevision() && !$transition->to()->isDefaultRevisionState()) + ) && ( + ($entity->isPublished() && $transition->to()->isPublishedState()) + || (!$entity->isPublished() && !$transition->to()->isPublishedState()) + )); } return TRUE; diff --git a/core/modules/content_moderation/src/Tests/ModerationFormTest.php b/core/modules/content_moderation/src/Tests/ModerationFormTest.php index 07d221d..d91c872 100644 --- a/core/modules/content_moderation/src/Tests/ModerationFormTest.php +++ b/core/modules/content_moderation/src/Tests/ModerationFormTest.php @@ -208,6 +208,33 @@ public function testContentTranslationNodeForm() { $this->drupalPostForm(NULL, [ 'body[0][value]' => 'Seventh version of the content.', ], t('Save and Create New Draft (this translation)')); + + // Make sure we're not allowed to create a forward french revision. + $this->drupalGet('fr/' . $edit_path); + $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)"]')); + + // We should be able to publish the english forward revision. + $this->drupalGet($edit_path); + $this->assertTrue($this->xpath('//input[@value="Save and Create New Draft (this translation)"]')); + $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.', + ], t('Save and Publish (this translation)')); + + // Make sure we're allowed to create a forward french revision. + $this->drupalGet('fr/' . $edit_path); + $this->assertTrue($this->xpath('//input[@value="Save and Create New Draft (this translation)"]')); + $this->assertTrue($this->xpath('//input[@value="Save and Publish (this translation)"]')); + $this->assertTrue($this->xpath('//input[@value="Save and Archive (this translation)"]')); + + // Make sure we're allowed to create a forward english revision. + $this->drupalGet($edit_path); + $this->assertTrue($this->xpath('//input[@value="Save and Create New Draft (this translation)"]')); + $this->assertTrue($this->xpath('//input[@value="Save and Publish (this translation)"]')); + $this->assertTrue($this->xpath('//input[@value="Save and Archive (this translation)"]')); } }