Commit 9f3231c1 authored by Mike Keran's avatar Mike Keran
Browse files

Issue #2341807 by mikeker: Configure collapsed-state of secondary filters fieldset

parent 7c812b62
......@@ -103,12 +103,12 @@ class better_exposed_filters_exposed_form_plugin extends views_plugin_exposed_fo
'#title' => t('Override secondary options fieldset'),
'#default_value' => $existing['general']['secondary_collapse_override'],
'#description' => t(
'This setting overrides the secondary options fieldset collapsed value.'
'This setting overrides the secondary options fieldset collapsed value. By default the fieldset renders opened if a value within is selected and closed otherwise.'
),
'#options' => array(
0 => t('Default'),
1 => t('Open'),
2 => t('Closed'),
1 => t('Always open'),
2 => t('Always closed'),
),
// Indent dependent options.
'#prefix' => '<div class="dependent-options">',
......@@ -795,30 +795,23 @@ dateFormat: "dd-mm-yy"
// search options"). Place this after the exposed filters and before the
// rest of the items in the exposed form.
if ($allow_secondary = $settings['general']['allow_secondary']) {
// If one of the secondary widgets has exposed input, do not collapse
// the secondary fieldset.
// If one of the secondary widgets has exposed input, do not collapse the
// secondary fieldset. Or is the "always open" or "always closed" option
// is selected, use that instead.
$secondary_collapse = TRUE;
$exposed_input = $this->view->get_exposed_input();
foreach ($this->display->handler->get_handlers('filter') as $label => $filter) {
if (!$filter->options['exposed']) {
continue;
}
if (!empty($exposed_input[$filter->options['expose']['identifier']]) && $settings[$label]['more_options']['is_secondary']) {
$secondary_collapse = FALSE;
break;
}
if ($settings['general']['secondary_collapse_override']) {
$secondary_collapse = $settings['general']['secondary_collapse_override'] == 2;
}
// Manual override for secondary options fieldset.
// If checked, make the fieldset open.
if ($override = $settings['general']['secondary_collapse_override']) {
switch ($override) {
case 1:
else {
$exposed_input = $this->view->get_exposed_input();
foreach ($this->display->handler->get_handlers('filter') as $label => $filter) {
if (!$filter->options['exposed']) {
continue;
}
if (!empty($exposed_input[$filter->options['expose']['identifier']]) && $settings[$label]['more_options']['is_secondary']) {
$secondary_collapse = FALSE;
break;
case 2:
$secondary_collapse = TRUE;
break;
}
}
}
......@@ -1866,7 +1859,7 @@ dateFormat: "dd-mm-yy"
),
'allow_secondary' => FALSE,
'secondary_label' => t('Advanced options'),
'secondary_collapse_override' => FALSE,
'secondary_collapse_override' => 0,
),
'sort' => array(
'bef_format' => 'default',
......
......@@ -698,10 +698,26 @@ class BEF_TestSecondaryFilters extends BEF_TestBase {
$this->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset/legend/span', 'Custom Label', 'Collapsible fieldset has the correct custom label');
$this->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset//select[@name="type[]"]', NULL, 'The node.type filter is within the secondary fieldset');
// Select an option and make sure the fielset is expanded when rendered.
// Select an option and make sure the fieldset is expanded when rendered.
$this->drupalGet('bef_test_page', array('query' => array('type' => 'page')));
$this->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset[contains(@class, "collapsible") and not(contains(@class, "collapsed"))]', NULL, 'Collapsible fieldset starts open');
// Verify force-open and force-closed fieldset options.
$this->setBefSettings(array(
// Always render opened.
'exposed_form_options[bef][general][secondary_collapse_override]' => 1,
));
$this->saveView();
$this->drupalGet('bef_test_page');
$this->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset[contains(@class, "collapsible") and not(contains(@class, "collapsed"))]', NULL, 'Collapsible fieldset starts open');
$this->setBefSettings(array(
// Always render closed.
'exposed_form_options[bef][general][secondary_collapse_override]' => 2,
));
$this->saveView();
$this->drupalGet('bef_test_page', array('query' => array('type' => 'page')));
$this->assertFieldByXpath('//div[@id="edit-secondary-wrapper"]//fieldset[contains(@class, "collapsible") and contains(@class, "collapsed")]', NULL, 'Collapsible fieldset starts closed');
// https://drupal.org/node/2189321
// Verify fieldset is collapsed/expanded when a custom filter ID is set.
// @TODO: Consider refactoring so we can leverage all existing tests to use
......@@ -709,6 +725,10 @@ class BEF_TestSecondaryFilters extends BEF_TestBase {
$this->editFilter('node.type', array(
'options[expose][identifier]' => 'custom_id',
));
$this->setBefSettings(array(
// Use default open/closed rendering.
'exposed_form_options[bef][general][secondary_collapse_override]' => 0,
));
$this->saveView();
$this->drupalGet('bef_test_page');
......
Supports Markdown
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