You are here

function name_field_autocomplete_query in Name Field 7

Name autocomplete sources query callback.

Handles the autocomplete for title and generational options.

Parameters

array $components: The keys that the autocomplete is active on.

string $base_string: Autocomplete strings are split and individual pieces are parsed sequentially. The base string is the concatanated results of previous segment lookups.

string $string: Current segment of the search string.

array|null $field: If run in the context of the Field API, the field is supplied.

int $limit:

mixed $arguments: Additional arguments defined in hook_name_data_sources().

Return value

array The matches ready to use directly in the autocomplete response.

2 string references to 'name_field_autocomplete_query'
hook_name_data_sources in ./name.api.php
Defines available name field autocomplete sources.
name_name_data_sources in ./name.module
Implements hook_name_data_sources().

File

./name.module, line 1176
Defines an API for displaying and inputing names.

Code

function name_field_autocomplete_query($components, $base_string, $string, $field, $limit, $arguments) {
  $component_key = $arguments;
  $matches = array();
  foreach (name_field_get_options($field, $component_key) as $key => $option) {
    if (strpos(drupal_strtolower($key), $string) === 0 || strpos(drupal_strtolower($option), $string) === 0) {
      $matches[$base_string . $key] = $key;
      $limit--;
    }
    if (!$limit) {
      break;
    }
  }
  return $matches;
}