You are here

function _autocomplete_widgets_get_options in Autocomplete Widgets for Text and Number Fields 6

Same name and namespace in other branches
  1. 7 autocomplete_widgets.common.inc \_autocomplete_widgets_get_options()

Fetch an array of options for the given widget.

Parameters

$field: The field description.

$string: Optional string to filter values on (used by autocomplete).

$match: Operator to match filtered name against, can be any of: 'contains', 'equals', 'starts_with'

$keys: Optional keys to lookup (the $string and $match arguments will be ignored).

$limit: If non-zero, limit the size of the result set.

Return value

An array of valid values in the form: array( key => value, ... )

3 calls to _autocomplete_widgets_get_options()
autocomplete_widgets_json in ./autocomplete_widgets.module
Menu callback; Retrieve a pipe delimited string of autocomplete suggestions.
autocomplete_widgets_process in ./autocomplete_widgets.module
Process an individual textfield autocomplete element.
autocomplete_widgets_validate in ./autocomplete_widgets.module
Validate a textfield autocomplete element.

File

./autocomplete_widgets.common.inc, line 31
Common functions for Autocomplete Widgets module.

Code

function _autocomplete_widgets_get_options($field, $string = '', $match = 'contains', $keys = NULL, $limit = NULL) {
  static $results = array();

  // Create unique id for static cache.
  if (!isset($keys) || !is_array($keys)) {
    $keys = array();
  }
  $cid = $field['field_name'] . ':' . $match . ':' . ($string !== '' ? $string : implode('-', $keys)) . ':' . $limit;
  if (!isset($results[$cid])) {
    if ($field['widget']['type'] == 'autocomplete_widgets_allowvals') {
      $results[$cid] = _autocomplete_widgets_get_options_allowvals($field, $string, $match, $keys, $limit);
    }
    else {
      if ($field['widget']['type'] == 'autocomplete_widgets_flddata') {
        $results[$cid] = _autocomplete_widgets_get_options_flddata($field, $string, $match, $keys, $limit);
      }
      else {
        $results[$cid] = array();
      }
    }
  }
  return $results[$cid];
}