When a logged in user resets their password at /user/password and clicks the submit button, they are being redirected to the frontpage.
How can I redirect to /user instead?
I've tried the second answer here: How to redirect users after password reset from first time user, but the redirect doesnt happen.
function myModule_form_user_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if ($form_state->get('user_pass_reset')) {
$form['actions']['submit']['#submit'][] = 'mymodule_form_submit';
}
}
function mymodule_form_submit(array $form, FormStateInterface $form_state){
$form_state->setRedirect('user.page');
}
For the route name I've tried both entity.user.canonical and user.page. I'm not sure if the code just isn't correct for Drupal 9 or I'm getting the route wrong, but I would expect an error in that case instead of the redirect just not happening.
entity.user.canonical
. Other than that, the code looks good. Are you sure the submit handler is being called?user.page
is a fine alternative.