Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The gap between the expectation of this working and the failure to work is large enough that i'm filing this as a bug report, at least for now.
User-related replacement tokens are not working for the send e-mail action (configured in advanced actions) when used on account creation related triggers.
That is, nothing is replaced for:
[user:mail]
[user:name]
[account:mail]
[account:name]
When using at least the following triggers:
"Trigger: When either creating a new user account or updating an existing"
"Trigger: After creating a new user account"
"Trigger: After updating a user account"
Comment | File | Size | Author |
---|---|---|---|
#3 | user-870868-account-tokens-when-saving-user.patch | 707 bytes | mlncn |
#2 | user-870868-user-account-when-saving.patch | 0 bytes | mlncn |
Comments
Comment #1
mlncn CreditAttribution: mlncn commentedSimilar problem reported in Drupal 6: #479218: Advanced Actions - Send email - Only global variables work - System Module
Comment #2
mlncn CreditAttribution: mlncn commentedHere is a patch that fulfills the expectation that user tokens will be available to actions when a user is being saved. User module's token integration was only checking for user account data in a sub-array called 'user', when more often (when not referring to the current user) the user account data is in a sub-array called 'account' (using account instead of user when the user being acted upon need not be the currently logged in user is best coding practice followed by in user.tokens.inc itself).
So long as both are checked (and this patch checks account first) token replacement works as expected. We can send an e-mail to an administrator whenever a user registers that includes that user's username and e-mail address. Joy!
[The magical disappearing patch... the one in the next comment will work better.]
Comment #3
mlncn CreditAttribution: mlncn commentedComment #4
pfrenssenI tested your patch against the latest drupal-7.x-dev.
Without applying your patch the [user:mail] and [user:name] tokens were correctly replaced in the email for me. The [account:mail] and [account:name] were not replaced, but applying the patch did not fix this. I had the exact same result with or without patch.
Exact steps I did to replicate the problem:
* installed drupal-7.x-dev with a clean db
* admin/modules > enabled the trigger module
* admin/config/system/actions > create advanced action > send email
I used these settings for the advanced action:
- Label: Send e-mail
- Recipient: (my email address, not using any tokens)
- Subject: test
- Message:
* admin/structure/trigger/user > assign "send e-mail" action to:
- Trigger: After creating a new user account
- Trigger: After updating a user account
(note: I did not assign this action to the "When either creating a new user account or updating an existing" trigger, because this option was not in the list)
* admin/people/create > added a new user with a random name, email and password
I received an email with the following body text:
* applied the patch in comment #3
* created a new user with a random name, email and password
Resulting email:
The patch did not have any effect. I tried to look up which tokens are available but couldn't find anything but the few examples in the actions config pages.
Comment #5
mgiffordWhere is this now?
I came here with a related issue where an upgraded site didn't update the tokens used in the emails here /admin/config/people/accounts
Still have to find the best place to post that, but want to know that this has been addressed.
Comment #6
Dave ReidThis is not the right fix. We need to fix what's providing the $data array.
Comment #7
TWD CreditAttribution: TWD commentedsubscribing
Comment #8
chegor CreditAttribution: chegor as a volunteer commentedTested with 7.50. All is ok for
[user:mail]
[user:name]
[user:edit-url]