How alter submit user_pass_reset? I can alter every form submit in Drupal with this hook:


  hook_form_alter


On the user_pass_reset form there is a button for auto-login from a link.

I need to add some custom logic just after the user click on the button "Login".

Here's how I tried to do that :

function tools_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){

   if($form_id == 'user_pass_reset')
    {   
        $form['actions']['submit']['#submit'][] = 'tools_compte_mot_de_passe_reset_submit';
        $form['#submit'][] = 'tools_compte_mot_de_passe_reset_submit';
    }
}


I have set the 2 form methods because I trying to understand which is called.


  My custom submit :


function tools_compte_mot_de_passe_reset_submit($form, \Drupal\Core\Form\FormStateInterface &amp;$form_state)
{
    exit();
}


My custom submit is never called... if I try on a different form, that works, but not on this one.

Where i am wrong ?
From \Drupal\user\Form\UserPasswordResetForm::buildForm:

&lt;?php
$form['#action'] = Url::fromRoute('user.reset.login', [
  'uid' =&gt; $user-&gt;id(),
  'timestamp' =&gt; $timestamp,
  'hash' =&gt; $hash,
])-&gt;toString();
?&gt;


If you look at the form in your browser, you can see that it directly POSTS to that other route. as a result of that, your submit isn't called because for that, it would need to actually submit to itself again.

That then points to \Drupal\user\Controller\UserController::resetPassLogin(), which calls user_login_finalize(), which calls user_login().

Depending on what you want to do on submit, you can either do in hook_user_login() or by altering that route.