You are here

function message_example_comment in Message 6

Implementation of hook_comment().

File

modules/message_example/message_example.module, line 68

Code

function message_example_comment(&$a1, $op) {
  if ($op == 'insert') {

    // The comment ID.
    $cid = $a1['cid'];

    // The node ID that has this comment.
    $nid = $a1['nid'];

    // The user is the comment author.
    $account = user_load($a1['uid']);
    $arguments = array(
      // The link will be replaced with the url of the node using url() upon
      // display. Even if the node alias changes, then the link will always be
      // displayed correctly.
      '@link' => array(
        'callback' => 'url',
        'callback arguments' => array(
          'node/' . $nid,
          array(
            'fragment' => 'comment-' . $cid,
          ),
        ),
      ),
      // Hard code the comment's subject.
      '@title' => $a1['subject'],
      // Custom callback to return the most up-to-date node title.
      '@node-title' => array(
        'callback' => 'message_example_node_title',
        'callback arguments' => array(
          $nid,
        ),
      ),
    );

    // Save the message and assign it to the user realm and node realm. The node
    // will allow us to see activity related to a single node.
    // As in the hook_nodeapi() implementation, we assign it to the comment
    // author instead of the acting user.
    $realms = array();
    $realms[] = array(
      'realm' => 'user',
      'realm id' => $account->uid,
    );
    $realms[] = array(
      'realm' => 'node',
      'realm id' => $nid,
    );
    message_save_message_to_realms('message_example_comment_insert', 'comment', $cid, $arguments, $realms, $account);
  }
}