function theme_select_as_hidden in Better Exposed Filters 7.3
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()
- 6.2 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
array $vars: An array of arrays, the 'element' item holds the properties of the element.
Return value
string HTML representing the form element.
See also
http://api.drupal.org/api/function/theme_select/7
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 166 - Provides theming functions to display exposed forms using different interfaces.
Code
function theme_select_as_hidden($vars) {
$element = $vars['element'];
$output = '';
$selected_options = empty($element['#value']) ? $element['#default_value'] : $element['#value'];
$properties = array(
'title' => isset($element['#title']) ? $element['#title'] : '',
'description' => isset($element['#bef_description']) ? $element['#bef_description'] : '',
'required' => FALSE,
);
foreach ($element['#options'] as $option => $elem) {
// Check for Taxonomy-based filters.
if (is_object($elem)) {
$slice = array_slice($elem->option, 0, 1, TRUE);
$option = key($slice);
$elem = current($slice);
}
// 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> element's
// original ID.
$id = drupal_html_id($element['#id'] . '-' . $key);
$hidden = array(
'id' => $id,
'name' => check_plain($element['#name']) . '[]',
'value' => check_plain($key),
);
$output .= theme('form_element', array(
'element' => array_merge($properties, array(
'#id' => $id,
'#children' => theme_hidden(array(
'element' => $hidden,
)),
)),
));
}
}
}
return $output;
}