message_notify_example.module in Message Notify 7
Same filename and directory in other branches
File
message_notify_example/message_notify_example.moduleView source
<?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.
return;
}
// 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 subject field' => 'field_message_rendered_subject',
'rendered body field' => 'field_message_rendered_body',
);
message_notify_send_mail($message, $options);
}
Functions
Name | Description |
---|---|
message_notify_example_comment_insert | Implements hook_comment_insert(). |