- Drupal version : 8.2.0
- Module "Better exposed filter" version : 8.x-3.0-alpha1

In short :

I created a view with an exposed filter. When I use the operator "is all of" from my exposed filter, all work. My exposed filter shows some tags in a select/option html list. I download and install the module "Better exposed filter" for display my exposed filter in checkbox instead the select/option html list. If I configure my exposed filter for it display checkboxs, then the view display no result.

In detail :

I created 3 simples contents of type 'articles' :

- Recipe one (tags 'ingredients' : salt, sugar )
- Recipe two (tags 'ingredients' : super, pepper )
- Recipe three (tags 'ingredients' : pepper, salt )

I created a very simple view :

Img1

Img2

When I do a search, I get two of my article if I select the tag "sugar" with the exposed operator "is all off" : (look the Query, **only one "INNER JOIN"**)

Img3

Tags exposed filter is an html select/option list. I want change this style by a list of checkboxs. So, I configure the filter style with the "better exposed filter" module :

Img4

When I do that, my view works when I search with the filter exposed operator "is one of". But when I use the filter exposed operator "is all off", no result displayed !

Img5

In the new query, I notice there are two "INNER JOIN". The second use an id = 0, the error must be here.

My questions are :

- Do I forget something in my configuration ?
- Is a bug in the module "better exposed filter" ?
- What should I do to operate the operand "is one off" when I display it in list of checkboxs ?

Thanks you :)

This thread is slightly different..the proposed patch was already in my code

CommentFileSizeAuthor
#8 taxonomy_views_filter_fix.zip2.51 KBdandaman

Comments

kegilko created an issue. See original summary.

kegilko’s picture

Issue summary: View changes
kegilko’s picture

Issue summary: View changes
nikolay borisov’s picture

I can confirm that there is a bug with the BEF checkbox filter output. When "Is all of" is selected.
The default drupal output (multiple select box works as it should, but the checkbox output is returning no values)

PS: also tested it with 8.3.0-alpha1

dandaman’s picture

I am also having this issue.

I have an exposed form for a taxonomy term. Without BEF, it is a select list with key term[]=25, and that works.

Within BEF and set to use checkboxes, the params submitted are like this:

type[25]=25&type[27]=27&type[26]=26

With this submission, Views seems to return no results. The database query looks like this:

SELECT DISTINCT node_field_data.title AS node_field_data_title, node_field_data.nid AS nid, node_field_data_node__field_node_locations.nid AS node_field_data_node__field_node_locations_nid
FROM 
{node_field_data} node_field_data
LEFT JOIN {node__field_node_locations} node__field_node_locations ON node_field_data.nid = node__field_node_locations.entity_id AND (node__field_node_locations.deleted = '0' AND node__field_node_locations.langcode = node_field_data.langcode)
INNER JOIN {node_field_data} node_field_data_node__field_node_locations ON node__field_node_locations.field_node_locations_target_id = node_field_data_node__field_node_locations.nid
LEFT JOIN {node__field_sub_brand} node__field_sub_brand ON node_field_data.nid = node__field_sub_brand.entity_id AND (node__field_sub_brand.deleted = '0' AND node__field_sub_brand.langcode = node_field_data.langcode)
INNER JOIN {node__field_lighting_type_filter} node__field_lighting_type_filter_value_0 ON node_field_data.nid = node__field_lighting_type_filter_value_0.entity_id AND node__field_lighting_type_filter_value_0.field_lighting_type_filter_target_id = '25'
INNER JOIN {node__field_lighting_type_filter} node__field_lighting_type_filter_value_1 ON node_field_data.nid = node__field_lighting_type_filter_value_1.entity_id AND node__field_lighting_type_filter_value_1.field_lighting_type_filter_target_id = '27'
INNER JOIN {node__field_lighting_type_filter} node__field_lighting_type_filter_value_2 ON node_field_data.nid = node__field_lighting_type_filter_value_2.entity_id AND node__field_lighting_type_filter_value_2.field_lighting_type_filter_target_id = '26'
INNER JOIN {node__field_lighting_type_filter} node__field_lighting_type_filter_value_3 ON node_field_data.nid = node__field_lighting_type_filter_value_3.entity_id AND node__field_lighting_type_filter_value_3.field_lighting_type_filter_target_id = '0'
LEFT JOIN {node__field_machine_name} node_field_data_node__field_node_locations__node__field_machine_name ON node_field_data_node__field_node_locations.nid = node_field_data_node__field_node_locations__node__field_machine_name.entity_id AND (node_field_data_node__field_node_locations__node__field_machine_name.deleted = '0' AND node_field_data_node__field_node_locations__node__field_machine_name.langcode = node_field_data_node__field_node_locations.langcode)
WHERE (( (node_field_data_node__field_node_locations__node__field_machine_name.field_machine_name_value = 'minnesota') )AND(( (node_field_data.status = '1') AND (node_field_data.type IN  ('manufacturer')) AND( (node__field_lighting_type_filter_value_0.field_lighting_type_filter_target_id = '25') AND (node__field_lighting_type_filter_value_1.field_lighting_type_filter_target_id = '27') AND (node__field_lighting_type_filter_value_2.field_lighting_type_filter_target_id = '26') AND (node__field_lighting_type_filter_value_3.field_lighting_type_filter_target_id = '0') ))))
ORDER BY node_field_data_title ASC
LIMIT 40 OFFSET 0

Note these snippets of the query:

INNER JOIN {node__field_lighting_type_filter} node__field_lighting_type_filter_value_3 ON node_field_data.nid = node__field_lighting_type_filter_value_3.entity_id AND node__field_lighting_type_filter_value_3.field_lighting_type_filter_target_id = '0'

WHERE [....] AND (node__field_lighting_type_filter_value_3.field_lighting_type_filter_target_id = '0')

Not sure where the zero join is coming from. Not sure where all the code that creates these joins is either.

Any tips or help on resolving this is much appreciated.

Welsby’s picture

Also hitting this issue, only occurs when using checkboxes as opposed to a select.

dandaman’s picture

It was noted by a colleague of mine that Better Exposed Filters does work right if "is one of", but not if "is all of". But I guess that makes sense as the 0 option wouldn't stop matches from happening.

By the time Views gets to submitting the form, it seems the checkboxes have a setting for each checkbox, like this:

$values['tid'] = array(
  '25' => '25',
  '27' => '27',
  '26' => '26',
  '21' => '0',
  '1' => '0',
....
);

That is, for each checkbox with a taxonomy term ID, if it is not checked, it's ID is set as a key and the value is set as "0".

In core/modules/views/src/Form/ViewsExposedForm.php:submitForm() function, it runs Checkboxes::getCheckedCheckboxes() to get rid of empty checkboxes. It then sends that in $view->exposed_raw_input[$key].

But then later in lib/Drupal/Core/Database/QueryCondition.php:addFilter(), it adds conditions for each of $this->handler->tableAliases. But in this case, the tableAliases does actually have a 0 option in it, which should not be there, in addition to the 25, 26 and 27 values I was expecting.

dandaman’s picture

StatusFileSize
new2.51 KB

A co-worker (jacerider) wrote this little module that creates a new Views field for taxonomy terms that filters out the unwanted checkboxes. This fixes the issue, but it's likely there's a better way to integrate this into the core Views code or the Better Exposed Filters module.

mikeker’s picture

mikeker’s picture

Forgot the tag...

mikeker’s picture

Title: Drupal 8, “is all of” view search doesn't work with the module “Better exposed filter” » "is all of" filter operator doesn't work with checkboxes

Retitling to better reflect the issue.

mikeker’s picture

Curious if the patch in #2687773: Using checkboxes with an "is all of" filter fails if any options are selected (comment #24) fixes this issue for you? Please post back here either way. I would love to fix this in core rather than hack around core in BEF!

Thanks.

mikeker’s picture

Status: Active » Closed (duplicate)

I'm closing this in favor of #2687773: Using checkboxes with an "is all of" filter fails if any options are selected which should fix the underlying issue here. Please test the patch in that issue and report back there if it fixes the problems you're seeing.