Problem/Motivation

I have a multi-value-accepting facets exposed filter using a BEF checkboxes element with the "Make filter options collapsible" option checked. The facets exposed filter is configured to order any selected options above deselected options.

If I check one box and submit the form, BEF's automatic opening mechanism fails and the filter remains collapsed (as if no selections were made). If I expand the filter I can see my single selection.

Checking two boxes works and the filter remains expanded after form submission.

Steps to reproduce

See above.

Proposed resolution

I think we should modify this code in BetterExposedFiltersWidgetBase to work with checkboxes:

       // Check if one or more values are set for our current element.
      $options = $form[$element]['#options'] ?? [];
      $default_value = $form[$element]['#default_value'] ?? key($options);
      $has_values = array_reduce($user_input, function ($carry, $value) use ($form, $element, $default_value) {
        return $carry || ($value === $default_value ? '' : ($value || $default_value === 0));
      }, FALSE);

Currently, in the case of a checkboxes element with no pre-checked default (so no $form[$element]['#default_value']), this code will incorrectly assume the first checkbox option to be the empty/default option, and if checked, incorrectly conclude that the element has no values set.

I think this could also be a problem for a required radio element where the first option is not an empty option.

Remaining tasks

MR + review.

User interface changes

Automatic opening of collapsible BEF checkboxes elements with a single selection.

API changes

None.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

chrisolof created an issue. See original summary.

chrisolof’s picture

Status: Active » Needs work

mxr576 made their first commit to this issue’s fork.

mxr576’s picture

Status: Needs work » Needs review

I do not know how to provide test coverage for this without adding Facets 3 as a dependency, did not find a way to configure a similar behavior as "The facets exposed filter is configured to order any selected options above deselected options." which is the culprit of the issue.

smustgrave’s picture

Status: Needs review » Needs work

If it’s just dealing with checkboxes should be able to provide test coverage, we got some existing ones as is

mxr576’s picture

@smustgrave tried that, added a new checkbox multivalue widget to bef_view but could not reproduce the issue, not even with sorting enabled on items. So the real culprit is the way how facets module reorders the active item to the top.

Since Facets 3 switched to BEF as dependency, maybe it becomes inevitable having a compatibility test suite with it since more and more issues popping up in BEF's issue queue from there. This is how I also got here this week :-)

smustgrave’s picture

Not in front of my computer does facets happen to have a test we can steal?

mxr576’s picture

Status: Needs work » Needs review

Checked quickly and I have only found a basic test coverage in the related sub module which might no be even using BEF in testing atm based on the export test view config :see-no-evil:

https://git.drupalcode.org/project/facets/-/tree/3.0.x/modules/facets_ex...

smustgrave’s picture

Status: Needs review » Fixed

I'll merge this without test coverage as that may be a whole thing. But eventually probably should have a facets related test added

  • smustgrave committed 30d820e5 on 7.1.x
    Issue #3512871 by mxr576, chrisolof: Automatic opening of collapsed...
smustgrave’s picture

Eventually will release 7.1.x so merged to that too.

mxr576’s picture

. But eventually probably should have a facets related test added

Agreed, thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.