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

Comments

ifrik created an issue. See original summary.

webcultist’s picture

I 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.

CountPacMan’s picture

A 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.

dragos-dumi’s picture

I 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.

dragos-dumi’s picture

Category: Bug report » Feature request
borisson_’s picture

Category: Feature request » Bug report

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.

borisson_’s picture

Discussed this with @swentel, we can read this from BooleanItem's field settings.

dragos-dumi’s picture

StatusFileSize
new5.96 KB

Added a patch with a processor to set On/Off values.
I will add a test soon.

borisson_’s picture

Status: Active » Needs work

This is looking great! Very cool.

  1. +++ b/src/Plugin/facets/processor/BooleanItemProcessor.php
    @@ -0,0 +1,155 @@
    + * Provides a count limit processor.
    

    Needs an update.

  2. +++ b/src/Plugin/facets/processor/BooleanItemProcessor.php
    @@ -0,0 +1,155 @@
    +   * Constructs a Drupal\Component\Plugin\PluginBase object.
    

    Needs an update.

  3. +++ b/src/Plugin/facets/processor/BooleanItemProcessor.php
    @@ -0,0 +1,155 @@
    +      '#states' => [
    +        'required' => ['input[name="facet_settings[boolean_item][status]"' => ['checked' => TRUE]],
    +      ],
    ...
    +      '#states' => [
    +        'required' => ['input[name="facet_settings[boolean_item][status]"' => ['checked' => TRUE]],
    +      ],
    

    Nice!

  4. +++ b/src/Plugin/facets/processor/BooleanItemProcessor.php
    @@ -0,0 +1,155 @@
    +  public function defaultConfiguration() {
    +    return array(
    +      'on_value' => 1,
    +      'off_value' => 0,
    +    );
    

    Let's use "On"/"Off" as default values here to have a sane default by just enabling the processor.

dragos-dumi’s picture

I've updated the patch.

dragos-dumi’s picture

StatusFileSize
new4.78 KB

I'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.

dragos-dumi’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 11: facets-boolean-label-2764659-tests.patch, failed testing.

borisson_’s picture

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!

borisson_’s picture

We can add our own fields on top of the already existing fields. This is already happening in HierarchicalFacetIntegrationTest

borisson_’s picture

Issue tags: +Needs reroll

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.

borisson_’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new10.87 KB

This combines #11 and #10.

Status: Needs review » Needs work

The last submitted patch, 17: no_labels_are_displayed-2764659-17.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new15.19 KB
new9.49 KB

Status: Needs review » Needs work

The last submitted patch, 19: no_labels_are_displayed-2764659-19.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review

Resting - that looks like a random fail,

  • borisson_ committed acb219d on 8.x-1.x
    Issue #2764659 by dragos-dumi, borisson_, ifrik: No labels are displayed...
borisson_’s picture

Status: Needs review » Fixed

Committed, thanks!

ifrik’s picture

Thanks a lot!

Status: Fixed » Closed (fixed)

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

Acha2019’s picture

@borisson ,

How to fix the issue in drupal 7

TKS