You are here

function message_example_node_insert in Message 7

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

Implements hook_node_insert().

File

message_example/message_example.module, line 22

Code

function message_example_node_insert($node) {

  // Save the message and assign it to the user realm. Since another user,
  // usually an admin might create the node, but populate the author field
  // with another user, we make sure the user is populated with the
  // node's author, instead of the acting user (although in most cases it
  // would be the same user).
  $message = message_create('example_create_node', array(
    'uid' => $node->uid,
  ));

  // 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_published
    ->set($node->status);
  $wrapper
    ->save();
}