You are here

function login_destination_form_alter in Login Destination 7

Same name and namespace in other branches
  1. 5 login_destination.module \login_destination_form_alter()

Implements hook_form_alter().

File

./login_destination.module, line 157
Control where users are directed to, once they login

Code

function login_destination_form_alter(&$form, &$form_state, $form_id) {

  // We redirect by using the drupal_goto_alter hook. If we simply
  // call drupal_goto() it may break compatibility with other modules. If we set
  // the $_GET['destination'] variable we will loose the possibility to redirect
  // to an external URL.
  // Please note the the system_goto_action() calls drupal_goto()
  // More on this issue http://drupal.org/node/732542.
  // If we add the $form_state['redirect'] here it will be overridden by the
  // user_login_submit(). So we add a submit handler instead and will set the
  // redirect later. Our submit handler will be executed after the execution
  // of user_login_submit(). This is because form_submit() functions are
  // appended to form before hook_form_alter() is executed.
  // We will execute also after LoginToboggan's function as it replaces the
  // original submit function from user module.
  switch ($form_id) {

    // User register page and user login page.
    case 'user_register_form':
    case 'user_login':
      $form['#validate'][] = 'login_destination_validate';
      break;
  }
  switch ($form_id) {

    // One-time login, password reset.
    case 'user_profile_form':
      if (isset($_GET['pass-reset-token'])) {

        // Redirect only from user_pass_reset
        // You have to explicitally turn on the option to always redirect from
        // the profile page. This is for constistency.
        $form['#submit'][] = 'login_destination_submit';
        break;
      }
  }
}