Problem/Motivation
When using a boolean field in a facet, no labels are displayed: neither the default "on/off" labels provided, nor is there an option to display the label text set in the field configuration.
Instead the two options are displayed as "0/1".

Proposed resolution
Display "on/off" by default since that is the default configuration of the field, and provide an option to display the label as provided by the field configuration instead.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | no_labels_are_displayed-2764659-19.patch | 9.49 KB | borisson_ |
Comments
Comment #2
webcultist commentedI would suggest the facet label or the field label as label for the checkbox.
have the same issue - tried "Translate entity label" to tick, but it breaks the site.
Comment #3
CountPacMan commentedA workaround is to jQuery a label in there:
$('[data-drupal-facet-item-id="facet_id"] span').text('Your label here');where facet_id is easily found by looking at the HTML output.
Additionally, you can set it to be a single checkbox if it is a boolean value by checking `exclude specified items` and excluding item `0` in the facet settings.
Comment #4
dragos-dumi commentedI would solve this one but I would first like to hear other opinions on the solution:
Add to the facet form another processor (similar with Count limit) - a checkbox "Boolean label" that will expand two input fields for On / Off values.
Showing labels from the field settings I'm not seeing it reliable because On/Off labels are per field instance and each instance could use different labels. Also boolean are Published, Sticky attributes, which don't have on/off labels.
Comment #5
dragos-dumi commentedComment #6
borisson_Another processor plugin is a good solution. I'm pretty sure we need to find a way to use the boolean's actual on/off values. But we can do that in a follow-up.
For now the way to resolve this is:
- Create a new processor (Display label for boolean fields)
- Transform into 0/1 On/Off.
- Open a followup to read the actual values from the config.
Comment #7
borisson_Discussed this with @swentel, we can read this from BooleanItem's field settings.
Comment #8
dragos-dumi commentedAdded a patch with a processor to set On/Off values.
I will add a test soon.
Comment #9
borisson_This is looking great! Very cool.
Needs an update.
Needs an update.
Nice!
Let's use "On"/"Off" as default values here to have a sane default by just enabling the processor.
Comment #10
dragos-dumi commentedI've updated the patch.
Comment #11
dragos-dumi commentedI've added a test, but it requires boolean field on the test data. Because the testing content structure comes from search_api, I'm not sure if I should open a ticket there or change this particular test to use a structure defined in facets module.
Comment #12
dragos-dumi commentedComment #14
borisson_Not sure how we should do that either. I'll discuss that with @drunken monkey to find a solution.
Huge thanks for the work you did on this!
Comment #15
borisson_We can add our own fields on top of the already existing fields. This is already happening in
HierarchicalFacetIntegrationTestComment #16
borisson_The patch in #11 doesn't apply anymore. It needs to be rerolled and merged with the patch in #10.
That's a good start to finish the test.
Comment #17
borisson_This combines #11 and #10.
Comment #19
borisson_Comment #21
borisson_Resting - that looks like a random fail,
Comment #23
borisson_Committed, thanks!
Comment #24
ifrikThanks a lot!
Comment #26
Acha2019 commented@borisson ,
How to fix the issue in drupal 7
TKS