You are here

public function BooleanOperator::getValueOptions in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/filter/BooleanOperator.php \Drupal\views\Plugin\views\filter\BooleanOperator::getValueOptions()

Return the possible options for this filter.

Child classes should override this function to set the possible values for the filter. Since this is a boolean filter, the array should have two possible keys: 1 for "True" and 0 for "False", although the labels can be whatever makes sense for the filter. These values are used for configuring the filter, when the filter is exposed, and in the admin summary of the filter. Normally, this should be static data, but if it's dynamic for some reason, child classes should use a guard to reduce database hits as much as possible.

2 calls to BooleanOperator::getValueOptions()
BooleanOperator::adminSummary in core/modules/views/src/Plugin/views/filter/BooleanOperator.php
Display the filter on the administrative summary.
BooleanOperator::valueForm in core/modules/views/src/Plugin/views/filter/BooleanOperator.php
Options form subform for setting options.

File

core/modules/views/src/Plugin/views/filter/BooleanOperator.php, line 129

Class

BooleanOperator
Simple filter to handle matching of boolean values.

Namespace

Drupal\views\Plugin\views\filter

Code

public function getValueOptions() {
  if (isset($this->definition['type'])) {
    if ($this->definition['type'] == 'yes-no') {
      $this->valueOptions = [
        1 => $this
          ->t('Yes'),
        0 => $this
          ->t('No'),
      ];
    }
    if ($this->definition['type'] == 'on-off') {
      $this->valueOptions = [
        1 => $this
          ->t('On'),
        0 => $this
          ->t('Off'),
      ];
    }
    if ($this->definition['type'] == 'enabled-disabled') {
      $this->valueOptions = [
        1 => $this
          ->t('Enabled'),
        0 => $this
          ->t('Disabled'),
      ];
    }
  }

  // Provide a fallback if the above didn't set anything.
  if (!isset($this->valueOptions)) {
    $this->valueOptions = [
      1 => $this
        ->t('True'),
      0 => $this
        ->t('False'),
    ];
  }
}