function _autocomplete_widgets_get_options_allowvals in Autocomplete Widgets for Text and Number Fields 6
Same name and namespace in other branches
- 7 autocomplete_widgets.common.inc \_autocomplete_widgets_get_options_allowvals()
Fetch an array of options for the given widget (allowed values).
Options are retrieved from the allowed values defined for the field.
1 call to _autocomplete_widgets_get_options_allowvals()
- _autocomplete_widgets_get_options in ./
autocomplete_widgets.common.inc - Fetch an array of options for the given widget.
File
- ./
autocomplete_widgets.common.inc, line 60 - Common functions for Autocomplete Widgets module.
Code
function _autocomplete_widgets_get_options_allowvals($field, $string = '', $match = 'contains', $keys = NULL, $limit = NULL) {
$function = $field['module'] . '_allowed_values';
$allowed_values = (array) (function_exists($function) ? $function($field) : content_allowed_values($field));
if (!isset($limit) || !is_numeric($limit)) {
$limit = count($allowed_values);
}
$case_insensitive = !empty($field['widget']['autocomplete_case']) ? FALSE : TRUE;
if ($case_insensitive && $match != 'equals') {
$string = drupal_strtolower($string);
}
$filter_xss = !empty($field['widget']['autocomplete_xss']);
$count = 0;
$options = array();
foreach ($allowed_values as $key => $value) {
if ($filter_xss) {
// Filter all HTML in $value, then trim white spaces.
$value = trim(filter_xss($value, array()));
}
if ($string === '') {
if (isset($keys) && is_array($keys)) {
if (in_array($key, $keys)) {
$options[$key] = $value;
$count++;
}
}
else {
$options[$key] = $value;
$count++;
}
}
else {
if ($match == 'equals') {
if ($value == $string) {
$options[$key] = $value;
$count++;
}
}
else {
$pos = strpos($case_insensitive ? drupal_strtolower($value) : $value, $string);
if ($match == 'starts_with' && $pos === 0 || $match == 'contains' && $pos !== FALSE) {
$options[$key] = $value;
$count++;
}
}
}
if ($count >= $limit) {
break;
}
}
return $options;
}