diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index eb3463dd895..e252d8e073e 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -95,6 +95,37 @@ class TermForm extends ContentEntityForm { return parent::form($form, $form_state); } + /** + * {@inheritdoc} + */ + protected function actions(array $form, FormStateInterface $form_state) { + $element = parent::actions($form, $form_state); + if (!$this->getRequest()->query->has('destination')) { + $element['overview'] = [ + '#type' => 'submit', + '#value' => $this->t('Save and go to list'), + '#weight' => 20, + '#submit' => array_merge($element['submit']['#submit'], ['::overview']), + ]; + } + + return $element; + } + + /** + * Form submission handler for the 'overview' action. + * + * @param array[] $form + * An associative array containing the structure of the form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + */ + public function overview(array $form, FormStateInterface $form_state): void { + $vocabulary = $this->entityTypeManager->getStorage('taxonomy_vocabulary') + ->load($form_state->getValue('vid')); + $form_state->setRedirectUrl($vocabulary->toUrl('overview-form')); + } + /** * {@inheritdoc} */ diff --git a/core/modules/taxonomy/tests/src/Functional/TermTest.php b/core/modules/taxonomy/tests/src/Functional/TermTest.php index 8612682157d..7faa59d083f 100644 --- a/core/modules/taxonomy/tests/src/Functional/TermTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TermTest.php @@ -407,6 +407,25 @@ class TermTest extends TaxonomyTestBase { // Assert that the term no longer exists. $this->drupalGet('taxonomy/term/' . $term->id()); $this->assertSession()->statusCodeEquals(404); + + // Test "save and go to list" action while creating term. + // Create the term to edit. + $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add'); + $edit = [ + 'name[0][value]' => $this->randomMachineName(12), + 'description[0][value]' => $this->randomMachineName(100), + ]; + + // Create the term to edit. + $this->submitForm($edit, 'Save and go to list'); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->addressEquals('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview'); + $this->assertSession()->pageTextContains($edit['name[0][value]']); + + // Validate that "Save and go to list" doesn't exist when destination + // parameter is present. + $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', ['query' => ['destination' => 'node/add']]); + $this->assertSession()->pageTextNotContains('Save and go to list'); } /**