We setup a flag with flag fields, and enabled on a node. We then set an action to send an email when the node was flagged. The admin screen for creating the action shows flagging:field type tokens available, but they are not replaced when the email is sent. Looking in the action code it appears that flag_actions_flag_flag receives the flagging entity, but does not pass it on to flag_actions_do, because there is no parameter available in flag_actions_do. With this patch I add an optional flagging parameter to flag_actions_do that defaults to "FALSE", then if that parameter is passed in I add it to the context array for token replacement. Seems to fix it for me.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Status: Active » Needs work

Thanks for the patch.

(I'm surprised anyone is still using actions rather than Rules...!)

  1. +++ b/flag_actions.module
    @@ -9,7 +9,7 @@
     function flag_actions_flag_flag($flag, $entity_id, $account, $flagging) {
    -  flag_actions_do('flag', $flag, $entity_id, $account);
    +  flag_actions_do('flag', $flag, $entity_id, $account, $flagging);
    

    You should make the same change to flag_actions_flag_unflag() to be consistent.

  2. +++ b/flag_actions.module
    @@ -203,7 +203,7 @@ function flag_actions_delete_action($aid) {
    +function flag_actions_do($event, $flag, $entity_id, $account, $flagging = FALSE) {
    

    The default should be NULL rather than FALSE.

    Also, I've no idea if this is something that other modules might feasibly call, so I'm not sure if the default is needed.

  3. +++ b/flag_actions.module
    @@ -235,6 +235,9 @@ function flag_actions_do($event, $flag, $entity_id, $account) {
    +      if($flagging){
    

    Check code formatting here.

ryan.wyse’s picture

Here is an updated patch. I dropped the default and the check for it, since you think its unlikely flag_actions_do would be in use anywhere else. And added in the unflag change.

cs_shadow’s picture

Status: Needs work » Needs review

Marking for review, though lgtm at a first glance.

@ryan.wyse, remember to set the status to 'Needs review' whenever you submit a patch. It serves two purposes:
1) Triggers the test bot.
2) Reviewers get to know that there's a patch that needs review.

timlie’s picture

Thanks for the patch, works for me!

bulldozer2003’s picture

This patch adds the flagging object to the trigger context as well.