Skip to content
Snippets Groups Projects
Commit 6299c024 authored by Nicolas Ricklin's avatar Nicolas Ricklin Committed by Jonathan Sacksick
Browse files

Issue #3292818 by Aerzas: Redirect state transition form to current path

parent f007ad22
No related branches found
No related tags found
2 merge requests!26Draft: Automated Project Update Bot fixes,!9Issue #3292818: Redirect state transition form to current path
Pipeline #119668 passed with warnings
......@@ -7,9 +7,17 @@ use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class StateTransitionForm extends FormBase implements StateTransitionFormInterface {
/**
* The redirect destination.
*
* @var \Drupal\Core\Routing\RedirectDestinationInterface
*/
protected $redirectDestination;
/**
* The entity.
*
......@@ -24,6 +32,15 @@ class StateTransitionForm extends FormBase implements StateTransitionFormInterfa
*/
protected $fieldName;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
$instance->redirectDestination = $container->get('redirect.destination');
return $instance;
}
/**
* {@inheritdoc}
*/
......@@ -114,7 +131,9 @@ class StateTransitionForm extends FormBase implements StateTransitionFormInterfa
$form['actions'][$transition_id] = [
'#type' => 'link',
'#title' => $transition->getLabel(),
'#url' => Url::fromRoute("entity.{$this->entity->getEntityTypeId()}.state_transition_form", $route_parameters),
'#url' => Url::fromRoute("entity.{$this->entity->getEntityTypeId()}.state_transition_form", $route_parameters, [
'query' => $this->redirectDestination->getAsArray(),
]),
'#attributes' => [
'class' => [
'button',
......
......@@ -126,7 +126,7 @@ class StateTransitionFormTest extends BrowserTestBase {
$this->assertSession()->pageTextContains('Test entity with bundle: First');
$this->assertSession()->pageTextContains('This action cannot be undone.');
$this->assertSession()->linkExists('Cancel');
$this->submitForm([], t('Confirm'));
$this->submitForm([], 'Confirm');
$buttons = $this->xpath('//form[@id="state-machine-transition-form-entity-test-with-bundle-field-state-1"]/div/a');
$this->assertCount(1, $buttons);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment