You are here

public function SwitchUserForm::submitForm in Devel 8.3

Same name and namespace in other branches
  1. 8 src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::submitForm()
  2. 8.2 src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::submitForm()
  3. 4.x src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/SwitchUserForm.php, line 100

Class

SwitchUserForm
Define a form to allow the user to switch and become another user.

Namespace

Drupal\devel\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // We cannot rely on automatic token creation, since the csrf seed changes
  // after the redirect and the generated token is not more valid.
  // TODO find another way to do this.
  $url = Url::fromRoute('devel.switch', [
    'name' => $form_state
      ->getValue('username'),
  ]);
  $url
    ->setOption('query', [
    'token' => $this->csrfToken
      ->get($url
      ->getInternalPath()),
  ]);
  $form_state
    ->setRedirectUrl($url);
}