You are here

function message_example_flag in Message 6

Implementation of hook_flag().

Add a message about users/ content being followed.

File

modules/message_example/message_example.module, line 113

Code

function message_example_flag($op, $flag, $content_id, $account, $fcid) {
  if ($op == 'flag') {
    $arguments = array();
    if ($flag->name == MESSAGE_EXAMPLE_FLAG_USER) {

      // User is following another user.
      $friend_account = user_load($content_id);

      // We don't need to save the whole user object, as we only need the partial
      // object to be used on display with theme_username().
      $dummy_account = new stdClass();
      $dummy_account->uid = $friend_account->uid;
      $dummy_account->name = $friend_account->name;
      $arguments = array(
        '!friend' => array(
          'callback' => 'message_example_theme_username',
          'callback arguments' => array(
            'account' => $dummy_account,
          ),
        ),
      );
    }
    elseif ($flag->name == MESSAGE_EXAMPLE_FLAG_NODE) {

      // User is following a node.
      $node = node_load($content_id);
      $arguments = array(
        '@link' => array(
          'callback' => 'url',
          'callback arguments' => array(
            'node/' . $node->nid,
          ),
        ),
        '@title' => $node->title,
      );
    }
    if ($arguments) {

      // Save the message to the user realm.
      message_save_message_to_realms($flag->name, $flag->content_type, $content_id, $arguments);
    }
  }
}