You are here

function search_api_node_access_records_alter in Search API 7

Same name and namespace in other branches
  1. 8 search_api.module \search_api_node_access_records_alter()

Implements hook_node_access_records_alter().

Marks the node as "changed" in indexes that use the "Node access" data alteration. Also marks the node's comments as changed in indexes that use the "Comment access" data alteration.

File

./search_api.module, line 949
Provides a flexible framework for implementing search services.

Code

function search_api_node_access_records_alter(&$grants, $node) {
  $conditions = array(
    'enabled' => 1,
    'read_only' => 0,
  );
  $indexes = search_api_index_load_multiple(FALSE, $conditions);
  foreach ($indexes as $index) {
    $item_ids = array();
    if (!empty($index->options['data_alter_callbacks']['search_api_alter_node_access']['status'])) {
      $item_id = $index
        ->datasource()
        ->getItemId($node);
      if ($item_id !== NULL) {
        $item_ids = array(
          $item_id,
        );
      }
    }
    elseif (!empty($index->options['data_alter_callbacks']['search_api_alter_comment_access']['status'])) {
      if (!isset($comments)) {
        $comments = comment_load_multiple(FALSE, array(
          'nid' => $node->nid,
        ));
      }
      foreach ($comments as $comment) {
        $item_ids[] = $index
          ->datasource()
          ->getItemId($comment);
      }
    }
    if ($item_ids) {
      search_api_track_item_change_for_indexes($index->item_type, $item_ids, array(
        $index->machine_name => $index,
      ));
    }
  }
}