Using hook_form_alter to change exposed filter from a textfield to a checkbox While Views in now in Core in Drupal 8, Better Exposed Filters, a popular module for Drupal 7, is not yet ported to Drupal 8.  So I need some way to do some of the same things.

I have an underlying Numerical field, and have configured an exposed filter that matches a value of 1 when the field has a value of > 0, and 0 otherwise. This works, but Views renders the field as a text field.  This is very ugly, and you'd think it would be simple enough to change the form field in the exposed filter form to a checkbox.  You'd think that changing the '#type' via hook_form_alter would do the job.

Except, this does not work. I've tracked the problem down to code in ViewExecutable::_build($key), around line 1269:


$rc = $handlers[$id]-&gt;acceptExposedInput($this-&gt;exposed_data);


If I change the '#type' of the form field to 'checkbox', $rc is always TRUE, even if when the type was still a textfield, $rc would be FALSE. This pretty much guarantees that the view will never return any matching rows.

The problem appears to be that the array ViewExecutable::$exposed_data have values of 1 (rather than the correct value of '') once type is changed to 'checkbox'.  Since ViewExecutable::$exposed_data has access "public", I still haven't figured out where in the code the wrong values get assigned.

I'm not sure why it's so hard to do something that is normally very simple using form_alter.  Any ideas as to how to get around this problem will make me (and my client) very happy.
Just entered this as a bug: https://www.drupal.org/node/2651102. The underlying issue is that Views checks for an empty array (among other things) to see if a filter has a value set. Unchecked checkboxes results in an array of zeros.