Commit a842c6e2 authored by Mike Keran's avatar Mike Keran
Browse files

Issue #1171952 by primerg: Add single on/off checkbox option for yes/no filters

parent 3a78e5d9
......@@ -5,7 +5,8 @@ Better Exposed Filters change log
Better Exposed Filters 6.x-2.0-xxxx xxxx-xx-xx
------------------------------------------------
Issue #1291994 by ressa: Adds node counts to taxonomy filters.
by mikeker: Added term depth limit option.
by mikeker: Added term depth limit option.
Issue #1171952 by primerg: Add single on/off checkbox option for yes/no filters
Better Exposed Filters 6.x-2.0-beta2 2011-08-03
......@@ -30,4 +31,4 @@ by mikeker: Branched Views 3.x support, removed from this branch.
Better Exposed Filters 6.x-1.0 2010-05-25
------------------------------------------
Initial release. Supports Views 2.x and 3.x.
\ No newline at end of file
Initial release. Supports Views 2.x and 3.x.
......@@ -88,6 +88,13 @@ function better_exposed_filters_form_alter(&$form, $form_state, $form_id) {
),
);
if ($form['options']['value']['#type'] == 'radios'
&& count($form['options']['value']['#options']) == 3
&& isset($form['options']['value']['#options'][1])
&& isset($form['options']['value']['#options'][0])) {
$left['bef_format']['#options']['bef_single'] = t('Single on/off checkbox');
}
// Build check all/none option form element
$right['bef_select_all_none'] = array(
'#type' => 'checkbox',
......@@ -121,7 +128,7 @@ function better_exposed_filters_form_alter(&$form, $form_state, $form_id) {
"Term A (4), Term B (10)", etc.'
),
);
// Add option to limit depth of hierarchical taxonomy vocabs
if ('views_handler_filter_term_node_tid_depth' == $form_state['handler']->definition['handler']) {
$options = array();
......@@ -138,7 +145,7 @@ function better_exposed_filters_form_alter(&$form, $form_state, $form_id) {
'Limit the depth of a hierarchical taxonomy filter to this depth. For example, if your taxonomy includes Country -> State -> City, setting a limit of 2 would show only Country and State in the filter.'
),
);
}
}
} // if (t('Taxonomy') == $form_state['handler']->definition['group']) {
} // if (in_array($form['options']['value']['#type'], $overrideable)) {
......@@ -178,16 +185,16 @@ function better_exposed_filters_form_alter(&$form, $form_state, $form_id) {
// Limit the depth of hierarchical taxonomy term filters
if (!empty($filter->options['expose']['bef_taxonomy_depth'])) {
$limit = $filter->options['expose']['bef_taxonomy_depth'];
// Because top level terms have no '-' prepended to them
// Because top level terms have no '-' prepended to them
$limit--;
$remaining = array();
foreach ($form[$field_id]['#options'] as $index => $option) {
if (!is_object($option)) {
// Most likely the "Any" option
$remaining[] = $option;
continue;
continue;
}
$option_text = $option->option;
if (!$option_text) {
......@@ -219,12 +226,30 @@ function better_exposed_filters_form_alter(&$form, $form_state, $form_id) {
// Intentionally falling through
case 'bef':
case 'bef_single':
$show_apply = TRUE;
if (empty($form[$field_id]['#multiple'])) {
// Single-select -- display as radio buttons
$form[$field_id]['#type'] = 'radios';
$form[$field_id]['#process'] = array('expand_radios', 'views_process_dependency');
// Use the single checkbox
if ($filter->options['expose']['bef_format'] == 'bef_single') {
$form[$field_id]['#type'] = 'checkbox';
$form[$field_id]['#title'] = $form['#info']["filter-$field_id"]['label'];
// Remove this option. We only need the values 1 and 0
unset($form[$field_id]['#options']['All']);
// Drupal core has a bug dealing with type checkbox. This is a
// fix to make sure the checkboxes are on and off based on user
// selection
if ($form_state['input'][$field_id] == 'All') {
$form[$field_id]['#default_value'] = 0;
$form_state['input'][$field_id] = 0;
}
$form[$field_id]['#value'] = $form_state['input'][$field_id];
}
// Clean up objects from the options array (happens for taxonomy-based filters)
$options = $form[$field_id]['#options'];
$form[$field_id]['#options'] = array();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment