You are here

function search_api_grouping_entity_insert in Search API Grouping 7.2

Implements hook_entity_insert().

Generates the necessary pseudo keys and adds the pseudo entities to to-index.

File

./search_api_grouping.module, line 86
Module search_api_grouping.

Code

function search_api_grouping_entity_insert($entity, $type) {

  // When inserting a new search index, the new index was already inserted into
  // the tracking table. This would lead to a duplicate-key issue, if we would
  // continue.
  // We also only react on entity operations for types with property
  // information, as we don't provide search integration for the others.
  if ($type == 'search_api_index' || !entity_get_property_info($type)) {
    return;
  }
  list($id) = entity_extract_ids($type, $entity);
  if (isset($id)) {

    // SearchApiDenormalizedEntityDataSourceController::trackItemChange()
    // accesses this static cache to ensure it uses the latest possible version
    // of the entity.
    $search_api_grouping_cache =& drupal_static('search_api_grouping_entity_op', array());
    $search_api_grouping_cache[$id] = clone $entity;
    search_api_track_item_insert(search_api_grouping_get_type($type), array(
      $id,
    ));

    // Clear cache.
    $search_api_grouping_cache = array();
  }

  // If index immediately is enabled we've to convert the ids.
  _search_api_grouping_index_immediatley_hijack($type, array(
    $id,
  ));
}