diff --git a/includes/callback_node_access.inc b/includes/callback_node_access.inc index 8bfab49..2db6eeb 100644 --- a/includes/callback_node_access.inc +++ b/includes/callback_node_access.inc @@ -38,17 +38,17 @@ class SearchApiAlterNodeAccess extends SearchApiAbstractAlterCallback { * {@inheritdoc} */ public function alterItems(array &$items) { - static $account; + static $implements_node_grants; - if (!isset($account)) { - // Load the anonymous user. - $account = drupal_anonymous_user(); + if (!isset($implements_node_grants)) { + // Check if there are any modules that implement hook_node_grants. + $implements_node_grants = count(module_implements('node_grants')); } foreach ($items as $id => $item) { $node = $this->getNode($item); - // Check whether all users have access to the node. - if (!node_access('view', $node, $account)) { + // Check implemented node_grants. + if ($implements_node_grants) { // Get node access grants. $result = db_query('SELECT * FROM {node_access} WHERE (nid = 0 OR nid = :nid) AND grant_view = 1', array(':nid' => $node->nid)); @@ -58,8 +58,7 @@ class SearchApiAlterNodeAccess extends SearchApiAbstractAlterCallback { } } else { - // Add the generic view grant if we are not using node access or the - // node is viewable by anonymous users. + // Add the generic view grant if we are not using node access. $items[$id]->search_api_access_node = array('node_access__all'); } }