I am trying to override default reset password functionality by using hook_form_FORM_ID_alter as below: The below code is written in custom module called usr_registration.module file
/**
* Implements hook_form_FORM_ID_alter().
*/
function usr_registration_form_user_pass_reset_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id, AccountInterface $user = NULL, $expiration_date = NULL, $timestamp = NULL, $hash = NULL) {
$form['account']['pass'] = [
'#type' => 'password_confirm',
'#size' => 25,
'#description' => t('Provide a password for the new account in both fields.'),
'#required' => TRUE,];
$form['#validate'][] = 'usr_registration_validate';
$form['actions']['submit']['#submit'][] = 'usr_registration_form_user_pass_reset_custom_submit';
}
// this function itself is not getting called
function usr_registration_validate(&$form, FormStateInterface $form_state) {
//unable to see below debug message and form is getting submitted
echo "I am here"; exit;
if($never_login) {
//some custom logic
} else {
//some custom logic
}
}
The important thing I noticed in UserPasswordResetForm class(user core module's form) is that there is no default validate method defined. I am unable to find out that why I cant alter the UserPasswordResetForm and custom validate handler over here.
note: My question is similar to this but not exactly same so please dont mark it as redundant.