diff --git a/core/modules/content_moderation/src/Plugin/Action/ModerationStateChange.php b/core/modules/content_moderation/src/Plugin/Action/ModerationStateChange.php index 9e5c66da05..27b765132f 100644 --- a/core/modules/content_moderation/src/Plugin/Action/ModerationStateChange.php +++ b/core/modules/content_moderation/src/Plugin/Action/ModerationStateChange.php @@ -85,24 +85,28 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta } } - $form['configuration'] = [ - '#type' => 'container', - '#id' => 'edit-configuration', - ]; + if (!$default_workflow = $form_state->getValue('workflow')) { + if (!empty($this->configuration['workflow'])) { + $default_workflow = $this->configuration['workflow']; + } + else { + $default_workflow = key($workflow_options); + } + } - $form['configuration']['workflow'] = [ + $form['workflow'] = [ '#type' => 'select', '#title' => $this->t('Workflow'), '#options' => $workflow_options, - '#default_value' => $this->configuration['workflow'], + '#default_value' => $default_workflow, '#required' => TRUE, '#ajax' => [ 'callback' => [static::class, 'configurationFormAjax'], - 'wrapper' => 'edit-configuration', + 'wrapper' => 'edit-state-wrapper', ], ]; - $form['configuration']['workflow_submit'] = [ + $form['workflow_submit'] = [ '#type' => 'submit', '#value' => $this->t('Change workflow'), '#limit_validation_errors' => [['workflow']], @@ -112,28 +116,26 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#submit' => [[static::class, 'configurationFormAjaxSubmit']], ]; - if (!$workflow = $form_state->getValue('workflow')) { - if (!empty($this->configuration['workflow'])) { - $workflow = $this->configuration['workflow']; + if ($default_workflow) { + $state_options = []; + foreach ($workflows[$default_workflow]->getTypePlugin()->getStates() as $state) { + $state_options[$state->id()] = $this->t('Change moderation state to @state', ['@state' => $state->label()]); } - else { - $workflow = key($workflow_options); - } - } - $state_options = []; - foreach ($workflows[$workflow]->getTypePlugin()->getStates() as $state) { - $state_options[$state->id()] = $this->t('Change moderation state to @state', ['@state' => $state->label()]); + $form['state-wrapper'] = [ + '#type' => 'container', + '#id' => 'edit-state-wrapper', + ]; + + $form['state-wrapper']['state'] = [ + '#type' => 'select', + '#title' => $this->t('State'), + '#options' => $state_options, + '#default_value' => $this->configuration['state'], + '#required' => TRUE, + ]; } - $form['configuration']['state'] = [ - '#type' => 'select', - '#title' => $this->t('State'), - '#options' => $state_options, - '#default_value' => $this->configuration['state'], - '#required' => TRUE, - ]; - return $form; } @@ -144,7 +146,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta * @see static::buildConfigurationForm() */ public static function configurationFormAjax($form, FormStateInterface $form_state) { - return $form['configuration']; + return $form['state-wrapper']; } /** diff --git a/core/modules/content_moderation/tests/src/FunctionalJavascript/ActionConfigurationTest.php b/core/modules/content_moderation/tests/src/FunctionalJavascript/ActionConfigurationTest.php index 2ea9d86362..54a08a77f8 100644 --- a/core/modules/content_moderation/tests/src/FunctionalJavascript/ActionConfigurationTest.php +++ b/core/modules/content_moderation/tests/src/FunctionalJavascript/ActionConfigurationTest.php @@ -99,8 +99,9 @@ public function testActionCreation() { $this->drupalPostForm('admin/config/system/actions', $edit, t('Create')); $assert_session->statusCodeEquals(200); $page = $this->getSession()->getPage(); - + $id = 'change_moderation_state_of_content'; $page->fillField('label', 'Change moderation state of content to draft'); + $page->fillField('id', $id); // Trigger the AJAX. $page->selectFieldOption('workflow', 'editorial'); $assert_session->assertWaitOnAjaxRequest(); @@ -111,7 +112,7 @@ public function testActionCreation() { $assert_session->addressEquals('admin/config/system/actions'); /** @var \Drupal\system\ActionConfigEntityInterface $action */ - $action = Action::load('change_moderation_state_of_content'); + $action = Action::load($id); $this->assertNotNull($action); /** @var \Drupal\content_moderation\Plugin\Action\ModerationStateChange $plugin */