You are here

function example_search_api_query_alter in Search API Autocomplete 7

Implements hook_search_api_query_alter().

This example hook implementation shows how a custom module could fix the problem with Views contextual filters in a specific context.

File

./search_api_autocomplete.api.php, line 439
Hooks provided by the Search API autocomplete module.

Code

function example_search_api_query_alter(SearchApiQueryInterface $query) {

  // Check whether this is an appropriate automcomplete query.
  if ($query
    ->getOption('search id') === 'search_api_autocomplete:example') {

    // If it is, add the necessary filters that would otherwise be added by
    // contextual filters. This is easy if the argument comes from the global
    // user or a similar global source. If the argument comes from the URL or
    // some other page-specific source, however, you would need to somehow pass
    // that information along to this function.
    global $user;
    $query
      ->condition('group', $user->data['group']);
  }
}