You are here

function hashtags_comment_insert in Hashtags 7

Implements hook_comment_insert().

File

./hashtags.module, line 311

Code

function hashtags_comment_insert($comment) {
  $field_name = variable_get('hashtags_terms_field', 'field_hashtags');
  $vid = variable_get('hashtags_vocabulary', 3);
  $entity_type = 'node';
  $entity = entity_load_single($entity_type, $comment->nid);
  $wrapper = entity_metadata_wrapper($entity_type, $entity);
  $bundle = $wrapper
    ->getBundle();

  // Check if field_hashtags field exists
  // for current entity
  if (!_hashtags_is_field_exists($field_name, $entity_type, $bundle)) {
    return;
  }

  // update all rows that have comment_id = 0
  // with comment_id that we have in this hook
  // because we don't have access to cid
  // from hook_comment_presave()
  db_update('hashtags_index')
    ->fields(array(
    'comment_id' => $comment->cid,
  ))
    ->condition('comment_id', 0)
    ->execute();
}