You are here

function search_exclude_nid_nodes_autocomplete in Search exclude nid 7

Autocomplete helper, $string = string to search for.

1 string reference to 'search_exclude_nid_nodes_autocomplete'
search_exclude_nid_menu in ./search_exclude_nid.module
Implements hook_menu().

File

./search_exclude_nid.admin.inc, line 90
Administrative page callbacks for the redirect module.

Code

function search_exclude_nid_nodes_autocomplete($string) {
  $matches = array();
  $query = db_select('node', 'n')
    ->fields('n', array(
    'nid',
    'title',
  ))
    ->condition('title', '%' . db_like($string) . '%', 'LIKE');

  // Remove already excluded nodes from the lookup.
  $excluded_nids = variable_get('search_exclude_nid_search_exclusion_nids', array());
  if (!empty($excluded_nids)) {
    $query
      ->condition('n.nid', $excluded_nids, 'NOT IN');
  }
  $result = $query
    ->execute();

  // Save the query to matches.
  foreach ($result as $row) {
    $matches[$row->nid] = check_plain($row->title);
  }

  // Return the result to the form in json.
  drupal_json_output($matches);
}