function theme_select_as_hidden in Better Exposed Filters 6.2
Same name and namespace in other branches
- 8.3 better_exposed_filters.theme \theme_select_as_hidden()
- 6.3 better_exposed_filters.theme \theme_select_as_hidden()
- 6 better_exposed_filters.theme \theme_select_as_hidden()
- 7.3 better_exposed_filters.theme \theme_select_as_hidden()
- 7 better_exposed_filters.theme \theme_select_as_hidden()
Themes a select element as a series of hidden fields
Parameters
object $element - An associative array containing the properties of the element.: Properties used: title, value, options, description
Return value
HTML string representing the form element.
See also
theme_select(), http://api.drupal.org/api/function/theme_select/6
1 string reference to 'theme_select_as_hidden'
- better_exposed_filters_theme in ./
better_exposed_filters.module - Implements hook_theme()
File
- ./
better_exposed_filters.theme, line 106
Code
function theme_select_as_hidden($element) {
$output = '';
$selected_options = (array) $element['#post'][$element['#name']];
// the selected keys from #options
$properties = array(
'title' => $element['#title'],
'description' => $element['#description'],
'required' => FALSE,
);
foreach ($element['#options'] as $option => $elem) {
// Check for Taxonomy-based filters
if (is_object($elem)) {
list($option, $elem) = each(array_slice($elem->option, 0, 1, TRUE));
}
/*
* Check for optgroups. Put subelements in the $element_set array and add a group heading.
* Otherwise, just add the element to the set
*/
$element_set = array();
if (is_array($elem)) {
$element_set = $elem;
}
else {
$element_set[$option] = $elem;
}
foreach ($element_set as $key => $value) {
// Only render fields for selected values -- no selected values renders zero fields
if (array_search($key, $selected_options) !== FALSE) {
// Custom ID for each hidden field based on the <select>'s original ID
$id = form_clean_id($element['#id'] . '-' . $key);
// Very similar to theme_hidden (http://api.drupal.org/api/function/theme_hidden/6)
$hidden = '<input type="hidden" ' . 'name="' . $element['#name'] . '[]" ' . 'id="' . $id . '" ' . 'value="' . check_plain($key) . '" ' . drupal_attributes($element['#attributes']) . ' />';
$output .= theme('form_element', array_merge($properties, array(
'#id' => $id,
)), $hidden);
}
}
}
return $output;
}