You are here

function message_example_comment_insert in Message 7

Same name and namespace in other branches
  1. 8 modules/message_example/message_example.module \message_example_comment_insert()

Implements hook_comment_insert().

File

message_example/message_example.module, line 40

Code

function message_example_comment_insert($comment) {
  $account = user_load($comment->uid);
  $node = node_load($comment->nid);
  $message = message_create('example_create_comment', array(), $account);

  // Save reference to the node in the node reference field, and the
  // "publish" state (i.e. if the node is published or unpublished).
  $wrapper = entity_metadata_wrapper('message', $message);
  $wrapper->field_node_ref
    ->set($node);
  $wrapper->field_comment_ref
    ->set($comment);

  // The message should be published only if the node and the comment are
  // both published.
  $published = $node->status && $comment->status;
  $wrapper->field_published
    ->set($published);
  $wrapper
    ->save();
}