Skip to main content
added 45 characters in body
Source Link

ForConcrete example of an exposed Boolean filter on the Order shipped field for the purchase page of the transactionsa 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';
  }
}

For an exposed Boolean filter on the Order shipped field for the purchase page of the transactions view of a custom entity in my rsc module in Drupal 8, I used the following. Note that I had to add _value to the field name.

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';
  }
}

Concrete example of an exposed Boolean filter for a view on a custom entity. Note that I had to add _value to field names.

  • 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';
  }
}
Source Link

For an exposed Boolean filter on the Order shipped field for the purchase page of the transactions view of a custom entity in my rsc module in Drupal 8, I used the following. Note that I had to add _value to the field name.

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';
  }
}