2

I am using the flag module to flag content.

Say user A flags a node. When user B updates the node, I want to send a mail to the user A (who flagged the node - I know I can use the Notifications and Messaging module but I want to send a notification in another way).

Is there an hook called when a flagged node is saved? So I can tap in on that hook and then retrieve a list of all users who flagged the node?

Thanks!

Paul

5
Is there an hook called when a flagged node is saved ?
  • No

However, you can use hook_node_update to trigger on a regular node save and check users who have flagged the current node ID.

You can also do most of the work without any coding using Rules, Views, Views Bulk Operations and obviously, Flag module.

2

I am using D6 and I use and implementation for the hook_nodeapi and hook_comment.

I am using a flag named follow. See the code below, maybe it can be of any help for someone.

This code returns a list of uids who have flagged the node which has changed (or has a new comment attached to it).

/**
 * Implementation of hook_nodeapi().
 */
function MYMODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {

  switch ($op) {
    case 'update':     
  // check if this node is flagged
  $flag_name = 'follow';
  $flag = flag_get_flag($flag_name);

  if($flag && $flag->is_flagged($node->nid)) {
     $list_uid = flag_get_content_flags(node, $node->nid, $flag_name, FALSE);
     $flags_by_uids = array();
     foreach($list_uid as $flags_by_uid)
     {
       $flags_by_uids[] = array($flags_by_uid->uid);
     }
  }
  break;
}
}
/**
 * Implementation of hook_comment().
 */
function MYMODULE_comment(&$a1, $op) {

  switch ($op) {
    case 'publish':
  // check if this node is flagged
  $flag_name = 'follow';
  $flag = flag_get_flag($flag_name);

  if($flag && $flag->is_flagged($a1[nid])) {
     $list_uid = flag_get_content_flags(node, $a1[nid], $flag_name, FALSE);
     $flags_by_uids = array();
     foreach($list_uid as $flags_by_uid)
     {
       $flags_by_uids[] = array($flags_by_uid->uid);
     }
  }
  break;
}
}
  • this really is helpful - at least for my own use. Thanks Paul! – AyeshK Jan 22 '13 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.