Loading core/modules/user/src/Hook/UserHooks.php +0 −10 Original line number Diff line number Diff line Loading @@ -304,16 +304,6 @@ public function userRoleDelete(RoleInterface $role): void { } } /** * Implements hook_element_info_alter(). */ #[Hook('element_info_alter')] public function elementInfoAlter(array &$types): void { if (isset($types['password_confirm'])) { $types['password_confirm']['#process'][] = 'user_form_process_password_confirm'; } } /** * Implements hook_modules_uninstalled(). */ Loading core/modules/user/src/Hook/UserThemeHooks.php +58 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ use Drupal\Component\Utility\Unicode; use Drupal\Core\Access\AccessibleInterface; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ThemeSettingsProvider; use Drupal\Core\Hook\Attribute\Hook; use Drupal\Core\Render\BubbleableMetadata; Loading @@ -24,8 +25,8 @@ class UserThemeHooks { public function __construct( protected AccountInterface $currentUser, protected ThemeSettingsProvider $themeSettingsProvider, protected ConfigFactoryInterface $configFactory, ) { } /** Loading Loading @@ -164,4 +165,60 @@ public function preprocessBlock(&$variables): void { } } /** * Implements hook_element_info_alter(). */ #[Hook('element_info_alter')] public function elementInfoAlter(array &$types): void { if (isset($types['password_confirm'])) { $types['password_confirm']['#process'][] = static::class . ':processPasswordConfirm'; } } /** * Form element process handler for client-side password validation. * * This #process handler is automatically invoked for 'password_confirm' form * elements to add the JavaScript and string translations for dynamic password * validation. * * @param array $element * The element being processed. * * @return array * The processed element */ public function processPasswordConfirm(array $element): array { $password_settings = [ 'confirmTitle' => $this->t('Passwords match:'), 'confirmSuccess' => $this->t('yes'), 'confirmFailure' => $this->t('no'), 'showStrengthIndicator' => FALSE, ]; if ($this->configFactory->get('user.settings')->get('password_strength')) { $password_settings['showStrengthIndicator'] = TRUE; $password_settings += [ 'strengthTitle' => $this->t('Password strength:'), 'hasWeaknesses' => $this->t('Recommendations to make your password stronger:'), 'tooShort' => $this->t('Make it at least 12 characters'), 'addLowerCase' => $this->t('Add lowercase letters'), 'addUpperCase' => $this->t('Add uppercase letters'), 'addNumbers' => $this->t('Add numbers'), 'addPunctuation' => $this->t('Add punctuation'), 'sameAsUsername' => $this->t('Make it different from your username'), 'weak' => $this->t('Weak'), 'fair' => $this->t('Fair'), 'good' => $this->t('Good'), 'strong' => $this->t('Strong'), 'username' => $this->currentUser->getAccountName(), ]; } $element['#attached']['library'][] = 'user/drupal.user'; $element['#attached']['drupalSettings']['password'] = $password_settings; return $element; } } core/modules/user/user.module +8 −30 Original line number Diff line number Diff line Loading @@ -622,38 +622,16 @@ function _user_mail_notify($op, AccountInterface $account) { * This #process handler is automatically invoked for 'password_confirm' form * elements to add the JavaScript and string translations for dynamic password * validation. * * @deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use * UserThemeHooks::processPasswordConfirm() instead. * * @see https://www.drupal.org/node/3582107 * @see Drupal\user\Hook\UserThemeHooks::processPasswordConfirm() */ function user_form_process_password_confirm($element) { $password_settings = [ 'confirmTitle' => t('Passwords match:'), 'confirmSuccess' => t('yes'), 'confirmFailure' => t('no'), 'showStrengthIndicator' => FALSE, ]; if (\Drupal::config('user.settings')->get('password_strength')) { $password_settings['showStrengthIndicator'] = TRUE; $password_settings += [ 'strengthTitle' => t('Password strength:'), 'hasWeaknesses' => t('Recommendations to make your password stronger:'), 'tooShort' => t('Make it at least 12 characters'), 'addLowerCase' => t('Add lowercase letters'), 'addUpperCase' => t('Add uppercase letters'), 'addNumbers' => t('Add numbers'), 'addPunctuation' => t('Add punctuation'), 'sameAsUsername' => t('Make it different from your username'), 'weak' => t('Weak'), 'fair' => t('Fair'), 'good' => t('Good'), 'strong' => t('Strong'), 'username' => \Drupal::currentUser()->getAccountName(), ]; } $element['#attached']['library'][] = 'user/drupal.user'; $element['#attached']['drupalSettings']['password'] = $password_settings; return $element; @trigger_error(__METHOD__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use UserThemeHooks::processPasswordConfirm() instead. See https://www.drupal.org/node/3582107', E_USER_DEPRECATED); return \Drupal::service(UserThemeHooks::class)->processPasswordConfirm($element); } /** Loading Loading
core/modules/user/src/Hook/UserHooks.php +0 −10 Original line number Diff line number Diff line Loading @@ -304,16 +304,6 @@ public function userRoleDelete(RoleInterface $role): void { } } /** * Implements hook_element_info_alter(). */ #[Hook('element_info_alter')] public function elementInfoAlter(array &$types): void { if (isset($types['password_confirm'])) { $types['password_confirm']['#process'][] = 'user_form_process_password_confirm'; } } /** * Implements hook_modules_uninstalled(). */ Loading
core/modules/user/src/Hook/UserThemeHooks.php +58 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ use Drupal\Component\Utility\Unicode; use Drupal\Core\Access\AccessibleInterface; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ThemeSettingsProvider; use Drupal\Core\Hook\Attribute\Hook; use Drupal\Core\Render\BubbleableMetadata; Loading @@ -24,8 +25,8 @@ class UserThemeHooks { public function __construct( protected AccountInterface $currentUser, protected ThemeSettingsProvider $themeSettingsProvider, protected ConfigFactoryInterface $configFactory, ) { } /** Loading Loading @@ -164,4 +165,60 @@ public function preprocessBlock(&$variables): void { } } /** * Implements hook_element_info_alter(). */ #[Hook('element_info_alter')] public function elementInfoAlter(array &$types): void { if (isset($types['password_confirm'])) { $types['password_confirm']['#process'][] = static::class . ':processPasswordConfirm'; } } /** * Form element process handler for client-side password validation. * * This #process handler is automatically invoked for 'password_confirm' form * elements to add the JavaScript and string translations for dynamic password * validation. * * @param array $element * The element being processed. * * @return array * The processed element */ public function processPasswordConfirm(array $element): array { $password_settings = [ 'confirmTitle' => $this->t('Passwords match:'), 'confirmSuccess' => $this->t('yes'), 'confirmFailure' => $this->t('no'), 'showStrengthIndicator' => FALSE, ]; if ($this->configFactory->get('user.settings')->get('password_strength')) { $password_settings['showStrengthIndicator'] = TRUE; $password_settings += [ 'strengthTitle' => $this->t('Password strength:'), 'hasWeaknesses' => $this->t('Recommendations to make your password stronger:'), 'tooShort' => $this->t('Make it at least 12 characters'), 'addLowerCase' => $this->t('Add lowercase letters'), 'addUpperCase' => $this->t('Add uppercase letters'), 'addNumbers' => $this->t('Add numbers'), 'addPunctuation' => $this->t('Add punctuation'), 'sameAsUsername' => $this->t('Make it different from your username'), 'weak' => $this->t('Weak'), 'fair' => $this->t('Fair'), 'good' => $this->t('Good'), 'strong' => $this->t('Strong'), 'username' => $this->currentUser->getAccountName(), ]; } $element['#attached']['library'][] = 'user/drupal.user'; $element['#attached']['drupalSettings']['password'] = $password_settings; return $element; } }
core/modules/user/user.module +8 −30 Original line number Diff line number Diff line Loading @@ -622,38 +622,16 @@ function _user_mail_notify($op, AccountInterface $account) { * This #process handler is automatically invoked for 'password_confirm' form * elements to add the JavaScript and string translations for dynamic password * validation. * * @deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use * UserThemeHooks::processPasswordConfirm() instead. * * @see https://www.drupal.org/node/3582107 * @see Drupal\user\Hook\UserThemeHooks::processPasswordConfirm() */ function user_form_process_password_confirm($element) { $password_settings = [ 'confirmTitle' => t('Passwords match:'), 'confirmSuccess' => t('yes'), 'confirmFailure' => t('no'), 'showStrengthIndicator' => FALSE, ]; if (\Drupal::config('user.settings')->get('password_strength')) { $password_settings['showStrengthIndicator'] = TRUE; $password_settings += [ 'strengthTitle' => t('Password strength:'), 'hasWeaknesses' => t('Recommendations to make your password stronger:'), 'tooShort' => t('Make it at least 12 characters'), 'addLowerCase' => t('Add lowercase letters'), 'addUpperCase' => t('Add uppercase letters'), 'addNumbers' => t('Add numbers'), 'addPunctuation' => t('Add punctuation'), 'sameAsUsername' => t('Make it different from your username'), 'weak' => t('Weak'), 'fair' => t('Fair'), 'good' => t('Good'), 'strong' => t('Strong'), 'username' => \Drupal::currentUser()->getAccountName(), ]; } $element['#attached']['library'][] = 'user/drupal.user'; $element['#attached']['drupalSettings']['password'] = $password_settings; return $element; @trigger_error(__METHOD__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use UserThemeHooks::processPasswordConfirm() instead. See https://www.drupal.org/node/3582107', E_USER_DEPRECATED); return \Drupal::service(UserThemeHooks::class)->processPasswordConfirm($element); } /** Loading