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"

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mlncn’s picture

mlncn’s picture

Status: Active » Needs review
Issue tags: +dgd7
FileSize
0 bytes

Here 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.]

mlncn’s picture

pfrenssen’s picture

I 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:

user:mail [user:mail]
user:name [user:name]
account:mail [account:mail]
account:name [account:name]

* 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:

user:mail test.test@test.com
user:name testuser
account:mail [account:mail]
account:name [account:name]

* applied the patch in comment #3
* created a new user with a random name, email and password

Resulting email:

user:mail nanad@nana.com
user:name chickenpox
account:mail [account:mail]
account:name [account:name]

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.

mgifford’s picture

Version: 7.x-dev » 7.0

Where 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.

Dave Reid’s picture

Version: 7.0 » 7.x-dev
Status: Needs review » Needs work

This is not the right fix. We need to fix what's providing the $data array.

TWD’s picture

subscribing

chegor’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Tested with 7.50. All is ok for
[user:mail]
[user:name]
[user:edit-url]