function theme_select_as_hidden in Better Exposed Filters 8.3
Same name and namespace in other branches
- 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.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
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
File
- ./
better_exposed_filters.theme, line 76 - 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>'s original ID.
$id = drupal_html_id($element['#id'] . '-' . $key);
// Very similar to theme_hidden()
// (http://api.drupal.org/api/function/theme_hidden/7).
// @TODO: Render in a template
$hidden = '<input type="hidden" ' . 'name="' . filter_xss($element['#name']) . '[]" ' . 'id="' . $id . '" ' . 'value="' . check_plain($key) . '" ' . drupal_attributes($element['#attributes']) . ' />';
// @TODO: Render in a template
$output .= theme('form_element', array(
'element' => array_merge($properties, array(
'#id' => $id,
'#children' => $hidden,
)),
));
}
}
}
return $output;
}