1

The problem:

When using hook_user_login to redirect a user to the correct language this is also triggered during password reset. And the hook params do not provide a way to deal with this.

This How can I redirect users on login based on their chosen language? post details multiple not working concepts.

And i can't comment cause of the silly reputation thing, while i'm a developer for over 10 years... (getting tired)

I guess the form alter is the ONLY way.

1

hook_user_login is as you'd expect for when someone goes from anonymous to authenticated. This happens by using the login form and by using a password reset link.

Having a look on Drupal's API site is always worthwhile as people have usually commented on comment occurances like this. For example on https://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/hook_user_login/7.x it has exactly what you're describing and recommends using something like:

if((!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset')){
  //your redirect code
}

But also using form_alter would also be perfectly fine really as you want to target a specific action of logging in via a specific form

  • 1
    For example: redirect to the user's language prefix on login / pass reset. Using HOOK_form_FORM_ID_alter (MODULE_form_user_login_alter) now (with a submit callback), works perfectly. – Rob C Oct 25 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.