ForConcrete example of an exposed Boolean filter on the Order shipped
field for the purchase
page of the transactions
a view ofon a custom entity in my rsc
module in Drupal 8, I used the following. Note that I had to add _value
to the field namenames.
- Custom module name:
rsc
- View machine name:
transactions
- Page machine name:
purchase
- Field name:
field_order_shipped
Actual code:
function rsc_form_views_exposed_form_alter(&$form, &$form_state)
{
if ($form['#id'] == 'views-exposed-form-transactions-purchase') {
$form['field_order_shipped_value']['#options']['All'] = 'Any';
$form['field_order_shipped_value']['#options']['1'] = 'Yes';
$form['field_order_shipped_value']['#options']['0'] = 'No';
}
}