function finder_find_choices in Finder 6
Same name and namespace in other branches
- 7 finder.module \finder_find_choices()
Postprocessing for returned finder_find options when mode is choices.
1 call to finder_find_choices()
- finder_find in ./
finder.module - Get a list of choices for form or results.
File
- ./
finder.module, line 1587 - The finder module.
Code
function finder_find_choices($finder, $finder_element_id, $options, $keywords, $match) {
if ($options) {
// If there are options, fetch some info about the field names.
$element =& finder_element($finder, $finder_element_id);
$filter = isset($element->settings['choices']['sanitization']['format']) ? $element->settings['choices']['sanitization']['format'] : 'filter_xss';
$fields =& $element->settings['choices']['field'];
foreach ($fields as $key => $field) {
$field_info[$key] = finder_split_field($field);
$field_names[$key] = finder_field_alias($finder_element_id, $field_info[$key]['table'], $field_info[$key]['field']);
}
// Create a new array where we will put the options to return.
$new_options = array();
// Iterate through the options.
foreach ($options as $option) {
// Simply case - there is only one field.
if (count($fields) === 1) {
// Add the field name to the option.
$option->field_name = end($field_names);
// Add the field name to the display_field property of the option too.
$option->display_field = $option->field_name;
// If doing "per_result" then switch the field name to the base field.
if ($element->settings['choices']['per_result']) {
$option->field_name = $option->base_field;
}
// Append this option to the array.
$new_options[] = finder_sanitize($option, $filter);
}
elseif (count($fields) > 1) {
if (is_null($keywords)) {
$matching_names = $field_names;
}
else {
$matching_names = array();
foreach ($field_names as $field_name) {
if (!empty($option->{$field_name . '_matched'})) {
$matching_names[] = $field_name;
}
}
}
if (count($matching_names) === 1) {
$option->field_name = end($matching_names);
$option->display_field = $option->field_name;
$new_options[] = finder_sanitize($option, $filter);
}
elseif (!empty($matching_names)) {
foreach ($matching_names as $matching_name) {
$new_option = drupal_clone($option);
$new_option->field_name = $matching_name;
$new_option->display_field = $new_option->field_name;
$new_options[] = finder_sanitize($new_option, $filter);
}
}
}
}
return $new_options;
}
return $options;
}