- 🇬🇧United Kingdom kiwimind
@quietone having just tested this and also being able to reproduce the issue, I'm interested in the workaround that you mentioned.
I'm not sure what you mean by "group filters". The only way this term currently makes sense to me is when reordering filters and assigning them to groups there. I hope I'm missing something obvious.
Currently without leaning towards custom code I'm unable to see how you might output the field labels rather than the True/False.
Thank you.
- 🇮🇳India roshni27
I was able to reproduce the issue, and I attempted to solve it using group filters. However, I noticed that the values for 'enable' and 'disable' were set to 1 and 2, which is incorrect. We actually need the values to be 0 for 'disable' and 1 for 'enable.' I have attached a screenshot for reference. If I have misunderstood, please correct me.
- 🇮🇳India Akhil Babu Chengannur
However, I noticed that the values for 'enable' and 'disable' were set to 1 and 2, which is incorrect.
This is because key-value options for 'True' and 'False' are hardcoded in getValueOptions() method of BooleanOperator class
if (!isset($this->valueOptions)) { $this->valueOptions = [1 => $this->t('True'), 0 => $this->t('False')]; }
whereas when grouping is enabled, groupForm() method in FilterPluginBase simply adds the options in the same order as they are added in the UI →
if (!empty($this->options['group_info']['optional']) && !$this->multipleExposedInput()) { $groups = ['All' => $this->t('- Any -')]; } foreach ($this->options['group_info']['group_items'] as $id => $group) { if (!empty($group['title'])) { $groups[$id] = $group['title']; } }
If "Grouping 1" and "Grouping 2" are rearraged, then values for 'enable' and 'disable' will also get changed. But filtering will work correctly.
When a boolean field is added as a filter the labels defined on that field will be used as the options in the selector rather than the default "True" / "False".
This fix will be visible when the field filter is exposed.Is this the correct approach to fix this problem? What if the boolean field is reused in another content type with another set of labels for the "on" and "off" states. How will we decide which option should be displayed in exposed filter.
Instead, could we provide a text field in the exposed filter configuration form to customize the values??
- Status changed to Needs review
11 months ago 12:00pm 11 January 2024 - Status changed to Active
11 months ago 3:56pm 11 January 2024 - 🇳🇱Netherlands Lendude Amsterdam
#3 and #9 outline nicely why we can't just use the field's labels, because the same field can have multiple sets of labels. So the goal set out in the title I don't think we can do.
The option set out in #9 where we provide fields in the boolean filter where you can configure this could work, but does that really offer much more value over just using a grouped filter for this? I don't think it does, so "Won't fix" for me, unless we can think of way to determine the values we should be using here