You are here

function autocomplete_widgets_json in Autocomplete Widgets for Text and Number Fields 7

Same name and namespace in other branches
  1. 6 autocomplete_widgets.module \autocomplete_widgets_json()

Menu callback; Retrieve the autocomplete suggestions.

1 string reference to 'autocomplete_widgets_json'
autocomplete_widgets_menu in ./autocomplete_widgets.module
Implementation of hook_menu().

File

./autocomplete_widgets.module, line 249
Provides autocomplete widgets for Text and Number fields.

Code

function autocomplete_widgets_json($entity_type, $bundle_name, $field_name, $string = '') {
  module_load_include('inc', 'autocomplete_widgets', 'autocomplete_widgets.common');
  $instance = field_info_instance($entity_type, $field_name, $bundle_name);
  $match = isset($instance['widget']['settings']['autocomplete_match']) ? $instance['widget']['settings']['autocomplete_match'] : 'contains';
  $matches = array();
  $options = _autocomplete_widgets_get_options($instance, $string, $match, NULL, 10);
  foreach ($options as $key => $label) {

    // Add a class wrapper for a few required CSS overrides.
    $matches[$label] = '<div class="reference-autocomplete">' . check_plain($label) . '</div>';
  }
  drupal_json_output($matches);
}