function _autocomplete_widgets_get_options_suggested in Autocomplete Widgets for Text and Number Fields 7
Fetch an array of options for the given widget (suggested).
Options are retrieved from the suggested values defined for the field.
1 call to _autocomplete_widgets_get_options_suggested()
- _autocomplete_widgets_get_options in ./
autocomplete_widgets.common.inc - Fetch an array of options for the given widget.
File
- ./
autocomplete_widgets.common.inc, line 195 - Common functions for Autocomplete Widgets module.
Code
function _autocomplete_widgets_get_options_suggested($instance, $string = '', $match = 'contains', $keys = NULL, $limit = NULL) {
$case_sensitive = !empty($instance['widget']['settings']['autocomplete_case']);
$options = explode("\n", $instance['widget']['settings']['suggested_values']);
$options = array_map('trim', $options);
$options = array_filter($options, 'strlen');
switch ($match) {
case 'contains':
case 'starts_with':
$matched_options = array();
$string = !$case_sensitive ? strtolower($string) : $string;
foreach ($options as $key => $option) {
$option = !$case_sensitive ? strtolower($option) : $option;
if ($match == 'contains' && strpos($option, $string) !== FALSE) {
$matched_options[] = $options[$key];
}
elseif ($match == 'starts_with' && strpos($option, $string) === 0) {
$matched_options[] = $options[$key];
}
}
$options = $matched_options;
break;
case 'equals':
if (in_array($string, $options, TRUE)) {
$options = array(
$string,
);
}
break;
}
_autocomplete_widgets_sort_options($options, $instance);
return $options;
}