diff --git a/core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php b/core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php index 8c6aadf..e64dc97 100644 --- a/core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php +++ b/core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php @@ -135,7 +135,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#type' => 'select', '#options' => $target_states, '#default_value' => isset($target_states[$default->id()]) ? $default->id() : NULL, - '#empty_option' => '-- Select moderation state --', + '#empty_option' => '- Select moderation state -', '#key_column' => $this->column, ]; $element['#element_validate'][] = array(get_class($this), 'validateElement'); diff --git a/core/modules/content_moderation/src/Tests/ModerationFormTest.php b/core/modules/content_moderation/src/Tests/ModerationFormTest.php index caa5380..778bc9a 100644 --- a/core/modules/content_moderation/src/Tests/ModerationFormTest.php +++ b/core/modules/content_moderation/src/Tests/ModerationFormTest.php @@ -49,7 +49,18 @@ public function testModerationForm() { $this->drupalGet($latest_version_path); $this->assertResponse(403); + // Try saving with no moderation state. + $this->drupalGet($edit_path); + $this->assertFieldsByValue($this->xpath('//select[@id="edit-moderation-state-0"]'), 'draft'); + $this->drupalPostForm($edit_path, [ + 'body[0][value]' => 'Second version of the content.', + 'moderation_state[0]' => '', + ], t('Save')); + $this->assertText('Please select a moderation state.'); + // Update the draft. + $this->drupalGet($edit_path); + $this->assertFieldsByValue($this->xpath('//select[@id="edit-moderation-state-0"]'), 'draft'); $this->drupalPostForm($edit_path, [ 'body[0][value]' => 'Second version of the content.', 'moderation_state[0]' => 'draft', @@ -61,11 +72,29 @@ public function testModerationForm() { $this->assertResponse(403); // Publish the draft. + $this->drupalGet($edit_path); + $this->assertFieldsByValue($this->xpath('//select[@id="edit-moderation-state-0"]'), 'draft'); $this->drupalPostForm($edit_path, [ 'body[0][value]' => 'Third version of the content.', 'moderation_state[0]' => 'published', ], t('Save')); + // Archive the published entity. + $this->drupalGet($edit_path); + $this->assertFieldsByValue($this->xpath('//select[@id="edit-moderation-state-0"]'), 'published'); + $this->drupalPostForm($edit_path, [ + 'body[0][value]' => 'Fourth version of the content.', + 'moderation_state[0]' => 'archived', + ], t('Save')); + + // Then back to Published so we can add a forward revision. + $this->drupalGet($edit_path); + $this->assertFieldsByValue($this->xpath('//select[@id="edit-moderation-state-0"]'), ''); + $this->drupalPostForm($edit_path, [ + 'body[0][value]' => 'Fifth version of the content.', + 'moderation_state[0]' => 'published', + ], t('Save')); + // The published view should not have a moderation form, because it is the // default revision. $this->drupalGet($canonical_path); @@ -78,8 +107,10 @@ public function testModerationForm() { $this->assertResponse(403); // Make a forward revision. + $this->drupalGet($edit_path); + $this->assertFieldsByValue($this->xpath('//select[@id="edit-moderation-state-0"]'), 'published'); $this->drupalPostForm($edit_path, [ - 'body[0][value]' => 'Fourth version of the content.', + 'body[0][value]' => 'Sixth version of the content.', 'moderation_state[0]' => 'draft', ], t('Save')); diff --git a/core/modules/content_moderation/src/Tests/ModerationStateTestBase.php b/core/modules/content_moderation/src/Tests/ModerationStateTestBase.php index 8574a99..d31c6b3 100644 --- a/core/modules/content_moderation/src/Tests/ModerationStateTestBase.php +++ b/core/modules/content_moderation/src/Tests/ModerationStateTestBase.php @@ -41,6 +41,9 @@ 'access content overview', 'use editorial transition create_new_draft', 'use editorial transition publish', + 'use editorial transition archive', + 'use editorial transition archived_draft', + 'use editorial transition archived_published', ]; /**