diff --git a/core/lib/Drupal/Core/Render/Element/Checkboxes.php b/core/lib/Drupal/Core/Render/Element/Checkboxes.php index 117f839..f61f794 100644 --- a/core/lib/Drupal/Core/Render/Element/Checkboxes.php +++ b/core/lib/Drupal/Core/Render/Element/Checkboxes.php @@ -127,4 +127,23 @@ public static function valueCallback(&$element, $input, FormStateInterface $form } } + /** + * 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. + */ + static 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); + } + } diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index 65a4161..6e93f34 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -1320,25 +1320,6 @@ 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 diff --git a/core/modules/views/src/Plugin/views/filter/InOperator.php b/core/modules/views/src/Plugin/views/filter/InOperator.php index 775585c..fb08c5f 100644 --- a/core/modules/views/src/Plugin/views/filter/InOperator.php +++ b/core/modules/views/src/Plugin/views/filter/InOperator.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\Unicode; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Render\Element\Checkboxes; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; use Drupal\Core\Form\OptGroup; @@ -307,7 +308,7 @@ 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']])) { + if (!empty($this->options['expose']['identifier']) && is_array($input[$this->options['expose']['identifier']]) && Checkboxes::detectEmptyCheckboxes($input[$this->options['expose']['identifier']])) { return FALSE; }