diff --git a/core/modules/user/src/Controller/UserAuthenticationController.php b/core/modules/user/src/Controller/UserAuthenticationController.php index 16cd0a5ba75..ec36f9fd641 100644 --- a/core/modules/user/src/Controller/UserAuthenticationController.php +++ b/core/modules/user/src/Controller/UserAuthenticationController.php @@ -259,7 +259,7 @@ class UserAuthenticationController extends ControllerBase implements ContainerIn } // Send the password reset email. - $mail = _user_mail_notify('password_reset', $account, $account->getPreferredLangcode()); + $mail = _user_mail_notify('password_reset', $account); if (empty($mail)) { throw new BadRequestHttpException('Unable to send email. Contact the site administrator if the problem persists.'); } diff --git a/core/modules/user/tests/src/Kernel/UserMailNotifyTest.php b/core/modules/user/tests/src/Kernel/UserMailNotifyTest.php index 521e80833cd..fc8e5ff58a1 100644 --- a/core/modules/user/tests/src/Kernel/UserMailNotifyTest.php +++ b/core/modules/user/tests/src/Kernel/UserMailNotifyTest.php @@ -94,4 +94,15 @@ class UserMailNotifyTest extends EntityKernelTestBase { $this->assertEmpty($this->getMails()); } + /** + * Tests the deprecated $langcode argument to _user_mail_notify(). + * + * @group legacy + */ + public function testUserMailNotifyLangcodeDeprecation() { + $account = $this->createUser(); + $this->expectDeprecation('Specifying the notification language using the $langcode parameter is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Omit the parameter. See https://www.drupal.org/node/3187082'); + _user_mail_notify('password_reset', $account, $account->getPreferredLangcode()); + } + } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index a1395f46569..383c093878e 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1030,8 +1030,10 @@ function user_role_revoke_permissions($rid, array $permissions = []) { * The user object of the account being notified. Must contain at * least the fields 'uid', 'name', and 'mail'. * @param string $langcode - * (optional) Language code to use for the notification, overriding account - * language. + * (deprecated) (optional) Language code to use for the notification, + * overriding account language. Specifying the notification language using + * the $langcode parameter is deprecated in drupal:9.2.0 and is removed from + * drupal:10.0.0. Omit the parameter. See https://www.drupal.org/node/3187082 * * @return array * An array containing various information about the message. @@ -1040,6 +1042,10 @@ function user_role_revoke_permissions($rid, array $permissions = []) { * @see user_mail_tokens() */ function _user_mail_notify($op, AccountInterface $account, $langcode = NULL) { + if ($langcode) { + @trigger_error('Specifying the notification language using the $langcode parameter is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Omit the parameter. See https://www.drupal.org/node/3187082', E_USER_DEPRECATED); + } + if (\Drupal::config('user.settings')->get('notify.' . $op)) { $params['account'] = $account; $langcode = $langcode ? $langcode : $account->getPreferredLangcode();