I want to overwrite the password suggestion tip that's configured in Drupal core to show
'Make it at least 14 characters' from 'Make it at least 12 characters'.
Or simply remove the whole password suggestion tips box.
This is the Drupal core code that I want to overwrite https://git.drupalcode.org/project/drupal/-/blob/9.5.0/core/modules/user/user.module#L1109
Below is my function I wrote in my module.
function mymodule_element_info_alter(array &$types) {
if (isset($types['password_confirm'])) {
$types['password_confirm']['#process'][] = 'mymodule_form_process_password_confirm';
}
}
function mymodule_form_process_password_confirm($element, $form_state) {
if (\Drupal::config('user.settings')->get('password_strength')) {
$password_settings['showStrengthIndicator'] = FALSE;
$password_settings += [
'tooShort' => t('Make it at least 14 characters'),
'username' => \Drupal::currentUser()->getAccountName(),
];
}
return $element;
}
And this is the result I get if I print out the elements
[#process] => Array
(
[0] => Array
(
[0] => Drupal\Core\Render\Element\PasswordConfirm
[1] => processPasswordConfirm
)
[1] => mymodule_form_process_password_confirm
[2] => user_form_process_password_confirm
[3] => password_policy_check_constraints_password_confirm_process
)
I think the problem is that the my module's function gets run after the core so it's doing the opposite of what I want it to do.
Do you know how I can run my function after the core? Is there other ways to do it? Or how to remove the whole password suggestion tips from the core?
Your module just run before the core.
The core's module weight is 0, and it has name 'user' is sorted after your module (mymodule). So, add a mymodule.install and set the weight of your module higher than 0 (override core) or higher than 10 (override password_policy also) The function you need to call is module_set_weight, refer to https://api.drupal.org/api/drupal/core%21includes%21module.inc/function/module_set_weight/9.0.x
Your mymodule.install should be something like: