You are here

function login_destination_form_user_form_alter in Login Destination 8

Same name and namespace in other branches
  1. 8.2 login_destination.module \login_destination_form_user_form_alter()

Implements hook_form_FORM_ID_alter() for user_form().

File

./login_destination.module, line 70
Control where users are directed to, once they login, register or logout.

Code

function login_destination_form_user_form_alter(array &$form, FormStateInterface $form_state) {
  if (isset($_GET['pass-reset-token'])) {

    // If the query parameter 'pass-reset-token' is set, it is assumed that the
    // user just used a one-time login url.
    // If we add the $form_state['redirect'] here it will be overriden by
    // \Drupal\user\Form\UserLoginForm::submitForm(). So we add a submit handler
    // instead and will set the redirect later. Our submit handler will be
    // executed after the execution of the submit handler of the user login
    // form. This is because form_submit() functions are appended to the form
    // before hook_form_alter() is invoked.
    $form['actions']['submit']['#submit'][] = 'login_destination_form_user_form_submit';
  }
}