You are here

function customerror_user_login_submit in Customerror 8

Form submission handler for user_login_form().

Redirects the user to the destination we set in after logging in. Feels like this shouldn't be necessary somehow, right? Weird

File

./customerror.module, line 118
Enables custom 404 (not found) and 403 (access denied) pages in Drupal with no need for creating real nodes under taxonomies.

Code

function customerror_user_login_submit(&$form, FormStateInterface $form_state) {

  // Check if a destination was set, probably on an exception controller.
  // @see \Drupal\user\Form\UserLoginForm::submitForm()
  $request = \Drupal::service('request_stack')
    ->getCurrentRequest();
  if (!$request->request
    ->has('destination')) {
    $form_state
      ->setRedirectUrl($url);
  }
  else {
    $request->query
      ->set('destination', $request->request
      ->get('destination'));
  }
}