Problem/Motivation

In No labels are displayed for boolean fields the option was added to configure an on/off label for boolean fields.

In some cases you don't want to show both boolean states. For example when showing a filter to display accessible solutions, you only want to see the TRUE option as no one will search for NOT accessible:

Proposed resolution

Hide the result when the label is empty.

Remaining tasks

Add help text to the label fields to indicate that the result will be hidden when it is left empty.

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpp created an issue. See original summary.

mpp’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
2.21 KB
mpp’s picture

Title: Add option to hide a label for boolean fields » Hide result for boolean fields when label is empty
mpp’s picture

FileSize
3.67 KB

Added tests.

mpp’s picture

FileSize
4.11 KB

Added some more tests.

Kipyomag’s picture

Hi mpp,
I apply 3006725_4.patch but when I leave empty off value and save Facet,
it does not work, a value is required !

mpp’s picture

Assigned: mpp » Unassigned
FileSize
4.35 KB
1.34 KB

Hi @Kipyomag, welcome and thank you for the feedback!

I updated the patch to make at least one label required (required if the other isn't filled in). This allows you to fill in either the On or Off value.

PS: I noticed you were not yet a confirmed user so I confirmed you. Welcome on Drupal.org!

Kipyomag’s picture

Ok thx for the new patch

PS: Thank you again ;)

nrackleff’s picture

I do want to show the label, but I can't find the place in the admin interface to set the on-off label so all I see is "1". Can someone point me in the right direction? I am using version 8.x-1.1 of the module.

mpp’s picture

Added a screenshot. Please review/test the patch.

nrackleff’s picture

Thanks @mmp for the screenshot. I figured out why I am not seeing the settings. It has to do with the 'supportsFacet' function being too restrictive. I've opened a new issue here in case anyone else experiences this problem. https://www.drupal.org/project/facets/issues/3010328

ippy’s picture

Thanks @mpp for the patch.
It works great and I can see it being widely adopted as its a common use-case that both values are better presented in UX terms via single checkbox or switch.

  • Facets 8.x-1.1
  • D8.6.0
  • PHP7.1.21
borisson_’s picture

Status: Needs review » Fixed

Yeah, this looks very solid. Thanks so much @mpp! Committed and pushed.

  • borisson_ committed c8414fd on 8.x-1.x authored by mpp
    Issue #3006725 by mpp: Hide result for boolean fields when label is...

Status: Fixed » Closed (fixed)

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