Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 292761

Using checkboxes with an "is all of" filter fails if any options are selected

$
0
0

Problem/Motivation

Followup from #2651102: Using checkboxes for exposed filters results in zero rows displaying, this was originally reported in the Better Exposed Filters issue queue, but has since been moved to Drupal core.

When using checkboxes to render exposed form options, the FormAPI returns unchecked checkboxes as 0 => 0 entries. This doesn't cause any problems with OR filter ("is any of") but does with AND filters ("is all of").

Steps to reproduce:

  1. Standard install (drush si standard -y --account-pass=admin) with some devel-generated content
  2. Create a new view and add the "Content: Has taxonomy term" filter, select the Tags vocabulary and Dropdown for the selection type, followed by "Apply and continue"
  3. Tick the "Expose" option
  4. Set the operator to "Is all of" and tick the "Allow multiple selections" option and click the Apply button
  5. Either add a form_alter similar to this
    function test_form_views_exposed_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
      $form['tid']['#type'] = 'checkboxes';
    }

    or enable the Better Exposed Filters module and set this filter to render as checkboxes.

  6. Select any of the term checkboxes and click Apply

No results are returned. If you look at the generated SQL you will see something similar to

INNER JOIN {taxonomy_index} taxonomy_index_value_0 ON node_field_data.nid = taxonomy_index_value_0.nid AND taxonomy_index_value_0.tid = '5'
INNER JOIN {taxonomy_index} taxonomy_index_value_1 ON node_field_data.nid = taxonomy_index_value_1.nid AND taxonomy_index_value_1.tid = '0'

Proposed resolution

Filter user input from the form state to remove the data of empty checkboxes.

Remaining tasks

  • Determine where to fix this issue: the ManyToOne filter handler or ViewsExposedForm::submitForm. See the patches in #23 and #24
  • Tests

User interface changes

Nope.

API changes

Nope.

Data model changes

Nope.


Viewing all articles
Browse latest Browse all 292761

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>