Created
January 9, 2015 12:27
-
-
Save vladdancer/b03281d2f804af13d7b3 to your computer and use it in GitHub Desktop.
From http://cgit.drupalcode.org/message_notify/tree/message_notify_example/message_notify_example.module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Code for the Message notify example feature. | |
*/ | |
include_once('message_notify_example.features.inc'); | |
/** | |
* Implements hook_comment_insert(). | |
* | |
* Send a message to the node author when a new comment is created. | |
*/ | |
function message_notify_example_comment_insert($comment) { | |
$node = node_load($comment->nid); | |
if ($comment->uid == $node->uid) { | |
// The comment author is also the node author, and we would ususally | |
// return early here, but since this is an example, we send an email | |
// anyway. | |
} | |
// Create a new message, assigned to the node author, and add a | |
// reference to the comment, so we can later use tokens related to that | |
// comment. | |
$message = message_create('comment_insert', array('uid' => $node->uid)); | |
$wrapper = entity_metadata_wrapper('message', $message); | |
$wrapper->field_comment_ref->set($comment); | |
// Let message-notify deliver the email, and send the message for us. | |
// We pass in the options the field names, that will be used to capture | |
// the rendered message, and provide an email log. | |
$options = array( | |
'rendered fields' => array( | |
'message_notify_email_subject' => 'field_message_rendered_subject', | |
'message_notify_email_body' => 'field_message_rendered_body', | |
), | |
); | |
message_notify_send_message($message, $options); | |
if (module_exists('message_subscribe')) { | |
// If Message-subscribe exists, let this example module use it. | |
message_subscribe_send_message('comment', $comment, $message, array('email' => $options)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment