I just fix a problem about "An illegal choice has been detected..." with module "better_exposed_filters"

Configuration :
- Module "better_exposed_filters" installed
- Create a view
- Expose a filter as collapsible checkbox with better exposed filter
- Check the filter option remember

Then go to your view
- Check one checkbox on the collapsible list and then submit (it work perfectly)
- Go to another page and come back to your view (or actualize the page)
- Then an error appear with message "An illegal choice has been detected..."
- As you can see, all checkboxes are checked

The bug came from the class "Drupal\views\Plugin\views\filter\FilterPluginBase"
To fix it, open the file and replace last line from the method : "storeExposedInput"
=> you must remove integer values : 0

$session[$this->options['expose']['identifier']] = $input[$this->options['expose']['identifier']];

TO

// Fix multiple checkbox (Illegal Choice has been detected)
$value = $input[$this->options['expose']['identifier']];
if($this->options['expose']['multiple'] && is_array($value)){
  $value = array_filter($value, function($value) {
    return $value !== 0;
  });
}

$session[$this->options['expose']['identifier']] = $value;

Sorry, but I can't make a pull request right now, but I hope it will help

Comments

Hussonkevin created an issue. See original summary.

mustanggb’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.4.x-dev
Component: Miscellaneous » views.module

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

elaman’s picture

Status: Active » Needs review
StatusFileSize
new898 bytes

Confirming the issue.

Using array_filter without any argument, should get rid of empty items in array. Here is the patch.

borisson_’s picture

Issue tags: +Needs tests

Can we reproduce this with drupal core only? We should add tests so that this problem doesn't reappear in the future.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dunebl’s picture

It looks like it is solving my problem with drupal core only:

Field exposed= floating number
Exposed filter type=unique
Operator=Is equal
Expose operator= yes

Hunk #1 succeeded at 1464 (offset -12 lines).

dunebl’s picture

#4 apply on 8.8.2 with offset

patching file core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
Hunk #1 succeeded at 1530 (offset 54 lines).

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

nimoatwoodway’s picture

#4 works for me against 8.8.5

hardik_patel_12’s picture

StatusFileSize
new1.06 KB

Re roll for 8.8.x-dev.

lendude’s picture

Status: Needs review » Needs work
Issue tags: -better exposed filters, -views, -remember values
mrinalini9’s picture

Rerolled patch to 8.8.x as #11 failed to apply.

hardik_patel_12’s picture

Status: Needs work » Needs review

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

lance lancelot’s picture

I tried to fix this bug with the above patches, but then there is always one item selected.
In addition to this I just set the array to NULL and that seems to be working for me:

if ($this->options['expose']['multiple'] && is_array($input[$this->options['expose']['identifier']])) {
  $input[$this->options['expose']['identifier']] = null;
}
dystopianblue’s picture

Patch in #13 fixed the error msg for me. Thanks!

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dunebl’s picture

patch #13 failed on 9.4:

patching file core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
Hunk #1 FAILED at 1530.
1 out of 1 hunk FAILED -- saving rejects to file core/modules/views/src/Plugin/views/filter/FilterPluginBase.php.rej

Version: 9.2.x-dev » 9.3.x-dev
davidxo’s picture

Rerolled #13 for 9.3.x

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Postponed (maintainer needs more info)

Wonder if #2568889: Views exposed text filter set to required shows an empty error and form error on page load solved this issue?

If not please reopen in "needs work" as it was tagged for tests.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Since there hasn't been a follow up going to close for now. If still a valid bug please reopen.

Thanks all!