You are here

function _quotes_autocomplete_citation in Quotes 7

Same name and namespace in other branches
  1. 5 quotes.module \_quotes_autocomplete_citation()
  2. 6 quotes.module \_quotes_autocomplete_citation()

Function to provide autocomplete for citation field.

Parameters

string $string: The string currently entered by the user.

Return value

array An array of matches in JSON format.

1 string reference to '_quotes_autocomplete_citation'
quotes_menu in ./quotes.module
Implements hook_menu().

File

./quotes.module, line 2409
The quotes module allows users to maintain a list of quotes that can be displayed in any number of administrator-defined quote blocks.

Code

function _quotes_autocomplete_citation($string) {
  $matches = array();
  $strlen = drupal_strlen($string);
  if ($strlen) {
    $result = db_query("SELECT citation FROM {quotes} WHERE LOWER(citation) LIKE LOWER(:string)", array(
      ':string' => ($strlen > 1 ? '%%' : '') . addslashes($string) . '%%',
    ));
    foreach ($result as $row) {
      $matches[$row->citation] = check_plain($row->citation);
    }
  }
  drupal_json_output($matches);
}