diff --git a/core/modules/content_moderation/src/EntityTypeInfo.php b/core/modules/content_moderation/src/EntityTypeInfo.php index 362dcddce4..04c43b60d8 100644 --- a/core/modules/content_moderation/src/EntityTypeInfo.php +++ b/core/modules/content_moderation/src/EntityTypeInfo.php @@ -371,6 +371,7 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id ->getHandler($entity->getEntityTypeId(), 'moderation') ->enforceRevisionsEntityFormAlter($form, $form_state, $form_id); + // List invalid transitions. $invalid_transitions = array_diff_key($this->validator->getPermittedTransitions($entity, $this->currentUser), $this->validator->getValidTransitions($entity, $this->currentUser)); if ($invalid_transitions) { $labels = array_map(function ($transition) { return $transition->label(); }, $invalid_transitions); @@ -407,6 +408,7 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id * @param string $hook */ public function preprocess(array &$variables, $hook) { + // Remove all form fields if there are no valid transitions. if (strpos($hook, '_edit_form') && $variables['form']['invalid_transitions']['#no_valid_transitions']) { $invalid_transitions = $variables['form']['invalid_transitions']; unset($variables['form']); diff --git a/core/modules/content_moderation/src/StateTransitionValidation.php b/core/modules/content_moderation/src/StateTransitionValidation.php index c1e278aed0..b8535e32ec 100644 --- a/core/modules/content_moderation/src/StateTransitionValidation.php +++ b/core/modules/content_moderation/src/StateTransitionValidation.php @@ -44,25 +44,8 @@ public function getValidTransitions(ContentEntityInterface $entity, AccountInter // want to only allow specific transitions. if (count($entity->getTranslationLanguages()) > 1 && $this->moderationInfo->hasForwardRevision($entity)) { $permitted_transitions = array_filter($permitted_transitions, function(Transition $transition) use ($entity) { - if (!$this->moderationInfo->isLatestRevision($entity) && $entity->isNewTranslation()) { - return FALSE; - } - - // The entity needs to be the latest and translation affected, or be - // 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()) - )); + // The entity needs to be the latest and translation affected. + return $this->moderationInfo->isLatestRevision($entity) && $entity->isRevisionTranslationAffected(); }); } diff --git a/core/modules/content_moderation/src/Tests/ModerationFormTest.php b/core/modules/content_moderation/src/Tests/ModerationFormTest.php index a2845a2316..a1a149e82b 100644 --- a/core/modules/content_moderation/src/Tests/ModerationFormTest.php +++ b/core/modules/content_moderation/src/Tests/ModerationFormTest.php @@ -167,24 +167,14 @@ public function testContentTranslationNodeForm() { 'body[0][value]' => 'Third version of the content.', ], t('Save and Create New Draft (this translation)')); - // Add another english revision (revision 4). + // It should not be possible to add a new english revision. $this->drupalGet($edit_path); - $this->assertTrue($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 Publish this Content.'); - $this->drupalPostForm(NULL, [ - 'body[0][value]' => 'Forth version of the content.', - ], t('Save and Create New Draft (this translation)')); - - // It should still only be possible to create draft revisions. - $this->drupalGet($edit_path); - $this->assertTrue($this->xpath('//input[@value="Save and Create New Draft (this translation)"]')); + $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 Publish this Content.'); + $this->assertText('It is not possible to Create New Draft, Publish this Content.'); - // Publish the french forward revision (revision 5). + // Publish the french forward revision (revision 4). $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)"]')); @@ -193,7 +183,7 @@ public function testContentTranslationNodeForm() { 'body[0][value]' => 'Fifth version of the content.', ], t('Save and Publish (this translation)')); - // Now we can publish the english (revision 6). + // Now we can publish the english (revision 5). $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)"]')); @@ -208,7 +198,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)"]')); - // Add a english forward revision (revision 7). + // Add a english forward revision (revision 6). $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)"]')); @@ -224,8 +214,7 @@ public function testContentTranslationNodeForm() { $this->assertFalse($this->xpath('//input[@value="Save and Archive (this translation)"]')); $this->assertText('It is not possible to Create New Draft, Publish, Archive this Content.'); - // We should be able to publish the english forward revision (revision 8)usa12pop - //. + // We should be able to publish the english forward revision (revision 7) $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)"]'));