You are here

function hashtags_entity_insert in Hashtags 7

Implementation of hook_entity_insert().

File

./hashtags.module, line 182

Code

function hashtags_entity_insert($entity, $entity_type) {
  if ($entity_type == 'comment') {
    return;
  }

  // hashtags generation proccess can be prevented if define
  // hashtags_ignore property
  if (isset($entity->hashtags_ignore) && $entity->hashtags_ignore) {
    return;
  }
  $field_name = variable_get('hashtags_terms_field', 'field_hashtags');
  $vid = variable_get('hashtags_vocabulary', 3);
  $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;
  }
  $entity_id = $wrapper
    ->getIdentifier();

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