Issue #3056258 by mohit_aghera, vakulrai, guilhermevp, adalbertov, ankithashetty, aleevas, anmolgoyal74, munish.kumar, paulocs, jeroendegloire, pameeela, quietone, Abhijith S, benjifisher, catch, xjm, John Cook, lokapujya: Allow redirection to vocabulary list terms page after creating a new term

merge-requests/859/head
webchick 2021-06-28 12:43:15 -07:00
parent adb24cf8a8
commit 5cc279bac0
2 changed files with 50 additions and 0 deletions

View File

@ -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}
*/

View File

@ -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');
}
/**