function theme_select_as_checkboxes in Better Exposed Filters 6
Same name and namespace in other branches
- 6.3 better_exposed_filters.theme \theme_select_as_checkboxes()
- 6.2 better_exposed_filters.theme \theme_select_as_checkboxes()
- 7.3 better_exposed_filters.theme \theme_select_as_checkboxes()
- 7 better_exposed_filters.theme \theme_select_as_checkboxes()
Themes a select element as a set of checkboxes
Parameters
array $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_checkboxes'
- better_exposed_filters_theme in ./
better_exposed_filters.module - Implements hook_theme()
1 theme call to theme_select_as_checkboxes()
- theme_select_as_checkboxes_fieldset in ./
better_exposed_filters.theme - Themes a select element as a collection of checkboxes enclosed in a collapsible fieldset
File
- ./
better_exposed_filters.theme, line 34
Code
function theme_select_as_checkboxes($element) {
if (!empty($element['#bef_nested'])) {
return theme('select_as_tree', $element);
}
// the selected keys from #options
$selected_options = !empty($element['#post'][$element['#name']]) ? (array) $element['#post'][$element['#name']] : $element['#default_value'];
$output = '<div class="bef-checkboxes">';
foreach ($element['#options'] as $option => $elem) {
if ('All' === $option) {
// TODO: 'All' text is customizable in Views
// No need for an 'All' option -- either unchecking or checking all the checkboxes is equivalent
continue;
}
// 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();
$is_optgroup = FALSE;
if (is_array($elem)) {
$output .= '<div class="bef-group">';
$output .= '<div class="bef-group-heading">' . $option . '</div>';
$output .= '<div class="bef-group-items">';
$element_set = $elem;
$is_optgroup = TRUE;
}
else {
$element_set[$option] = $elem;
}
foreach ($element_set as $key => $value) {
$output .= bef_checkbox($element, $key, $value, array_search($key, $selected_options) !== FALSE);
}
if ($is_optgroup) {
$output .= '</div></div>';
// Close group and item <div>s
}
}
$output .= '</div>';
// Fake theme_checkboxes() which we can't call because it calls theme_form_element() for each option
$class = 'class="form-checkboxes bef-select-as-checkboxes';
$class .= isset($element['#attributes']['class']) ? ' ' . $element['#attributes']['class'] : '';
$class .= '"';
// Add exposed filter description
$description = '';
if (!empty($element['#description'])) {
$description = '<div class="description">' . $element['#description'] . '</div>';
}
return "<div {$class}>{$description}{$output}</div>";
}