Password reset invalid mail notify language

Created on 25 February 2022, almost 3 years ago
Updated 3 March 2023, almost 2 years ago

Problem/Motivation

If user try to reset password, via route /user/password and is anonymous. Mail get language default of site not current language.
password reset config is translated

Steps to reproduce

  1. Add two languan En and Ro, default is EN
  2. Go to /user/password
  3. Change language to RO
  4. Set mail to reset
  5. Mail that reveice is EN not current site language RO

Proposed resolution

As per the issue reporter, it's better to introduce a mail language hook than fetching the language from user detection method and set it for the password reset flow. As per @Utilvideo, if we introduce a new language hook then user will be set the language as per their requirements.

So as a solution I have introduced a new hook - hook_user_mail_language_alter() through which user will be set the language as per their choice for any user related mail functionality. Also added a new test - testUserPasswordResetHookLanguage() to test this new hook.

Remaining tasks

User interface changes

API changes

Added a new hook in core/modules/user/user.api.php - hook_user_mail_language_alter()

Data model changes

Release notes snippet

In function _user_mail_notify is not set current language of site

  public function submitForm(array &$form, FormStateInterface $form_state) {
    $account = $form_state->getValue('account');
    if ($account) {
      // Mail one time login URL and instructions using current language.
      $mail = _user_mail_notify('password_reset', $account);
🐛 Bug report
Status

Needs work

Version

9.5

Component
Language system 

Last updated about 18 hours ago

  • Maintained by
  • 🇩🇪Germany @sun
Created by

🇲🇩Moldova pavelculacov Chisinau

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇲🇩Moldova pavelculacov Chisinau

    @anup.sinha. Thanks working like i needed.

    function imberia_user_user_mail_language_alter(AccountInterface $account, &$language) {
      if( Drupal::currentUser()->isAnonymous()){
        $language = Drupal::languageManager()->getCurrentLanguage()->getId();
      }
    }
    

    Thank you again. And you are welcome to own social network.Imberia

  • 🇮🇳India anup.sinha Bengaluru

    Hi @Utilvideo,

    I am happy to hear that the solution is working as you expected. So can you please now merge it into 9.5 and 10 branches if everything looks good.

    Thanks & Regards,
    Anup

  • 🇲🇩Moldova pavelculacov Chisinau

    Changes will be integrate in Drupal Core?

  • 🇮🇳India anup.sinha Bengaluru

    Hi @Utilvideo, I was just thinking that it would be good if we can integrate the patch into Drupal core as the issue exists in Drupal 8, 9 and 10 versions. Please let me know your thoughts on this.

    Thanks & Regards,
    Anup

  • 🇲🇩Moldova pavelculacov Chisinau

    I think, this changes must be in core.

    Thanks.

  • Status changed to Needs work almost 2 years ago
  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India anup.sinha Bengaluru

    Hi @Utilvideo,

    Now I have found out why my earlier patch failed to apply for the automated test run here but working fine in local. I created the patch from 9.5.0 as this was the installed version in my local but here for the automated test run the version is 9.5.x. The dictionary.txt file is different in 9.5.x compare 9.5.0 and that is why the last patch failed to apply here.

    So here is my updated patch created for 9.5.x version.

    Thanks & Regards,
    Anup

  • Status changed to Needs work almost 2 years ago
  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    Did not test.

    But this will need an issue summary update for the proposed solution, helps the committers later.
    Also with a new api this will need a change record.

    Thanks.

  • Status changed to Needs review almost 2 years ago
  • Status changed to Needs work almost 2 years ago
  • 🇺🇸United States smustgrave

    Removing issue summary update but still will need a change record.

  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India anup.sinha Bengaluru

    Change record added for the new hook - hook_user_mail_language_alter().

  • Status changed to Needs work almost 2 years ago
  • 🇺🇸United States smustgrave

    Removing change record.

    1 NIT is the addition of the dictionary.txt should be alphabetic but that's being added to the bottom.

    D10 patch would be needed too.

  • 🇮🇳India TanujJain-TJ

    Adding a reroll patch for drupal: 10.1.x, please review.

  • Status changed to Needs review almost 2 years ago
  • Status changed to Needs work almost 2 years ago
  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Production build 0.71.5 2024