function SwitchUserForm::submitForm

Same name in other branches
  1. 5.x src/Form/SwitchUserForm.php \Drupal\devel\Form\SwitchUserForm::submitForm()

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);
}