[user: ] tokens in password reset email are not replaced

Created on 11 October 2023, 9 months ago
Updated 18 January 2024, 5 months ago

Problem/Motivation

On the Override tab, I enabled & imported user elements.
Now user tokens are not replaced in password reset emails. Only [site: ] tokens are replaced.

Steps to reproduce

Password reset emails provide their own 'user' context token data. And user tokens are replaced AFTER text formatters are applied to the text.
If text formatters use Replace tokens with the Replace empty values option checked, tokens will be removed from the text and the mail provider will already have text without tokens.

πŸ’¬ Support request
Status

Closed: works as designed

Version

1.3

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine super_romeo Kiev

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

Comments & Activities

  • Issue created by @super_romeo
  • Status changed to Postponed: needs info 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    You raised πŸ› Override settings may be wrong after upgrade from 1.2.x Fixed which was very similar. Then your issue title got changed. Is this definitely different from the other issue? Do you see the problem on a clean install of 1.3 (without upgrade from 1.2).

    Anyway I commented on the other issue, and I'll comment the same again:

    It works for me. UserEmailBuilder::build passes the callback user_mail_tokens.

  • πŸ‡ΊπŸ‡¦Ukraine bohart Lutsk, Ukraine

    As we use Drupal Symfony Mailer on our projects, I have tested the topic also (as I need to be sure user emails work well).
    Everything works well / as expected. So, I decided to write down this comment here as well. Hopefully, this comment (and testing) will be helpful for further decisions on this issue for the maintainer.

    @super_romeo, if the issue still exists, please provide the exact step-by-step instructions (from vanilla Drupal install) for reproducing the issue and re-open this task.
    If it still occurs, this will help to find and fix the source of the issue.
    This will significantly help everyone to be sure that user emails work correctly! As it's an important part of most projects.

    @AdamPS, as for now, I assume this issue can be marked as closed (without a fix required).
    Thanks!

  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    Great thanks @bohart

    I assume this issue can be marked as closed (without a fix required).

    Normally I leave it as postponed for a month or two to allow the OP to add more info. I agree after that it can be closed "cannot reproduce"

  • πŸ‡ΊπŸ‡¦Ukraine super_romeo Kiev

    Thank you for your support!
    But issue still stands.

    Steps:
    Uninstall module.
    Install version 1.4.0-beta2.
    Setup SMTP transport.
    On Overridetab opposite the Users click Enable and import.
    Send email. Tokens are replaced OK.

    Create text formatter with filter Replace tokens with the Replace empty values option checked.
    On Policy tab on User (Password recovery) click Edit.
    Change format to just created formatter and save.
    Send email. Use tokens are replaced with "".

  • Status changed to Active 8 months ago
  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    Aha thanks @super_romeo for a clear report - now I understand.

    The text formatter you have created is removing the tokensπŸ˜ƒ. I suggest you change the text format. I can't see any way to change this module that would help you.

  • πŸ‡ΊπŸ‡¦Ukraine super_romeo Kiev

    I guess user-context should be passed to text format filters.
    But I don't know how...

    Since it's related not only to password reset mail but all User mails, this issue is going to be quite popular soon :(

  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    Since it's related not only to password reset mail but all User mails, this issue is going to be quite popular soon :(

    No I think the problem is the text format on your siteπŸ˜ƒ.

  • Also got the same problem. The custom text format i use, is not able to render the [user:...] tokens. I need the custom format, because i have to render some html tags. Im not sure, but why is the "plain_text" format able to render the user tokens, and some custom format not? Do i miss some configurations?

  • I found now a solution:

    1. Remove global token replacement from your custom formatter
    2. Uninstall the symfony mailer module
    3. Install the symfony mailer module again (I installed 1.4.0)
    4. Enable & Import User & User Registration Password Overrides at /admin/config/system/mailer/override
    5. Go to the /admin/config/system/mailer and edit the html value of one of the settings
    6. Change the format to your custom formatter & save.

    Hope, this will help.

  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    This module renders user tokens correctly.

    The text format runs first, and it can't render user tokens. If the text format has "Replace empty values" then the tokens are lost, and this module cannot render them.

  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    I don't see the "replace tokens" filter - perhaps it comes from a contrib module?? Anyone that's what causes the problem.

  • πŸ‡ΊπŸ‡¦Ukraine super_romeo Kiev

    Filter named Replaces global and entity tokens with their values from token_filter module.

  • Status changed to Closed: works as designed 8 months ago
  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    Thanks for explaining. Closing because I see no bug. The site has a text format that removes the tokens and that's why they are missing.

  • πŸ‡ΊπŸ‡¦Ukraine Taran2L Lviv

    This module renders user tokens correctly.

    The text format runs first, and it can't render user tokens. If the text format has "Replace empty values" then the tokens are lost, and this module cannot render them.

    Yes, tokens do work, but this is exactly the problem. Symfony mailer should finishing building raw email and only then use a filter, like a last step in the pipeline

    For example, filtering HTML does break some tokens in some situations. Should we create a new issue for that?

Production build 0.69.0 2024