You are here

function commons_like_votingapi_insert in Drupal Commons 7.3

Implements hook_votingapi_insert(). Create a message when a user likes a node.

File

modules/commons/commons_like/commons_like.module, line 38

Code

function commons_like_votingapi_insert($votes) {
  foreach ($votes as $vote) {
    if ($vote['tag'] == 'commons_like' && $vote['entity_type'] == 'node') {
      $node = node_load($vote['entity_id']);
      $message = message_create('commons_like_user_likes_node', array(
        'uid' => $vote['uid'],
        'timestamp' => $vote['timestamp'],
      ));
      $wrapper = entity_metadata_wrapper('message', $message);
      $wrapper->field_target_nodes[] = $node;
      $wrapper
        ->save();
    }
  }
}