diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index b31e32b..5efd80b 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -1325,6 +1325,25 @@ public function storeGroupInput($input, $status) { } /** + * Determines if the submitted checkbox values include a selected option. + * + * @param array $input + * Form values returned from a set of checkboxes. + * + * @return bool + * TRUE if all options are unchecked. FALSE otherwise. + */ + public function detectEmptyCheckboxes(array $input) { + // Checkboxes show up as an array in the form of option_id => bool. If all + // the values are zero, then there is no input. + $checked = array_filter($input, function($value) { + return $value !== 0; + }); + + return empty($checked); + } + + /** * Determines if the input from a filter should change the generated query. * * @param array $input @@ -1356,17 +1375,6 @@ public function acceptExposedInput($input) { if ($value == 'All' || $value === array()) { return FALSE; } - - // Checkboxes show up as an array in the form of option_id => bool. - // If all the values are zero, then there is no input. - if (is_array($value)) { - $checked = array_filter($value, function($value) { - return $value !== 0; - }); - if (empty($checked)) { - return FALSE; - } - } } if (!empty($this->alwaysMultiple) && $value === '') { diff --git a/core/modules/views/src/Plugin/views/filter/InOperator.php b/core/modules/views/src/Plugin/views/filter/InOperator.php index 042dca5..775585c 100644 --- a/core/modules/views/src/Plugin/views/filter/InOperator.php +++ b/core/modules/views/src/Plugin/views/filter/InOperator.php @@ -287,15 +287,17 @@ public function reduceValueOptions($input = NULL) { return $options; } + /** + * @inheritdoc + */ public function acceptExposedInput($input) { - // A very special override because the All state for this type of - // filter could have a default: if (empty($this->options['exposed'])) { return TRUE; } - // If this is non-multiple and non-required, then this filter will - // participate, but using the default settings, *if* 'limit is true. + // The "All" state for this type of filter could have a default value. If + // this is a non-multiple and non-required option, then this filter will + // participate, but using the default settings *if* 'limit' is true. if (empty($this->options['expose']['multiple']) && empty($this->options['expose']['required']) && !empty($this->options['expose']['limit'])) { $identifier = $this->options['expose']['identifier']; if ($input[$identifier] == 'All') { @@ -303,6 +305,12 @@ public function acceptExposedInput($input) { } } + // If checkboxes are used to render this filter, we do not include the + // filter if all option are unchecked. + if (!empty($this->options['expose']['identifier']) && is_array($input[$this->options['expose']['identifier']]) && $this->detectEmptyCheckboxes($input[$this->options['expose']['identifier']])) { + return FALSE; + } + return parent::acceptExposedInput($input); }