In the current configuration, I have set up an email notification when content is flagged. I also have a user-account field "name" and "firstname" that I want to use in the automated email. Hence, I use this as my mail body in the rules action:
Dear Coordinator,
Mr. [flagging-user:field-name] has reserved a table.

[flagging-user:field-name] does not get replaced at all, while [flagging-user:name] yields the user name. Are profile fields not supported?

kind regards,
David

CommentFileSizeAuthor
#7 flag_1304790.patch876 bytesdrewish
#2 flag_user_global.patch473 bytesfago

Comments

quicksketch’s picture

Title: flagged-user fields not replaced » flagged-user sub-tokens not replaced

Updating title for accuracy. I haven't tried to use the flagging-user token in Drupal 7 yet, but if [flagging-user:name] works then it should work for all Field module fields also.

fago’s picture

StatusFileSize
new473 bytes

They are. I guess though the problem is that the global user object is taken, which is no full entity. Attached patch should fix it, please test.

fago’s picture

Status: Active » Needs review
quicksketch’s picture

Ah right. I actually just ran into this earlier this week that the global $user is not a full entity. Thanks for the patch, I imagine it should work, but if @dkliewer can confirm that would be great.

joachim’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev

Status: Needs review » Needs work

The last submitted patch, flag_user_global.patch, failed testing.

drewish’s picture

Title: flagged-user sub-tokens not replaced » flagging-user sub-tokens not replaced
StatusFileSize
new876 bytes

Looks like the code has moved into flag_flag.inc but the fix still works. Here's a re-roll.

drewish’s picture

Status: Needs work » Needs review
joachim’s picture

Status: Needs review » Fixed

Thanks for the reroll. Committed to 3.x.

joachim’s picture

Version: 7.x-3.x-dev » 7.x-2.x-dev

Fixed on 7x-2x too.

joachim’s picture

Status: Fixed » Needs work

Hmmmmm hang on.

This is adding a full user_load() right at the top of the process, for tokens we might or might not need.

Would it not be better for performance to leave this off until Rules is invoked (if it exists)?

Similarly, when we replace our own tokens for our own labels, we lazy-load the flagging entity:

  function replace_tokens($label, $contexts, $options, $entity_id) {
    if (strpos($label , 'flagging:') !== FALSE) {
      if (($flagging = $this->get_flagging($entity_id))) {
        $contexts['flagging'] = $flagging;
      }
    }
    return token_replace($label, $contexts, $options);
  }

Should we not take the same approach for the user here?

joachim’s picture

Hmmyup, on further reflection, I'm not happy with this fix. I don't think it's a good thing to be adding an extra entity load to the flag pathway, which is used on AJAX.

Reverting the commits.

  • joachim committed 7ee68bf on 8.x-4.x authored by fago
    Issue #1304790 by fago, drewish: Fixed flagging-user sub-tokens not...
  • joachim committed 9cd5e72 on 8.x-4.x
    Revert "Issue #1304790 by fago, drewish: Fixed flagging-user sub-tokens...
ivnish’s picture

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

Drupal 7 is EOL. Issue will be closed, but patches are still here