Advertisement
MrJoshMiller

Untitled

Jun 13th, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. /**
  2.  * Implements hook_comment_insert().
  3.  *
  4.  * Send a message when a new comment is created to subscribed users.
  5.  */
  6. function dc_subscribe_comment_insert($comment) {
  7.   // must confirm $comment->status
  8.  
  9.   // Create a new message, assigned to the node author, and add a
  10.   // reference to the comment, so we can later use tokens related to that
  11.   // comment.
  12.   $message = message_create('comment_message_v2', array('uid' => $comment->uid));
  13.   $wrapper = entity_metadata_wrapper('message', $message);
  14.   // Reference field to the comment on the message
  15.   $wrapper->field_comment_reference->set($comment);
  16.   // Reference field to the node that was commented on
  17.   $wrapper->field_node_comment_reference->set($comment->nid);
  18.  
  19.   // Let Message-subscribe save and send notifications.
  20.   message_subscribe_send_message('comment', $comment, $message);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement