function BooleanOperator::valueForm

Same name in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/filter/BooleanOperator.php \Drupal\views\Plugin\views\filter\BooleanOperator::valueForm()
  2. 10 core/modules/views/src/Plugin/views/filter/BooleanOperator.php \Drupal\views\Plugin\views\filter\BooleanOperator::valueForm()
  3. 11.x core/modules/views/src/Plugin/views/filter/BooleanOperator.php \Drupal\views\Plugin\views\filter\BooleanOperator::valueForm()

Overrides FilterPluginBase::valueForm

File

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

Class

BooleanOperator
Simple filter to handle matching of boolean values.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function valueForm(&$form, FormStateInterface $form_state) {
    if (empty($this->valueOptions)) {
        // Initialize the array of possible values for this filter.
        $this->getValueOptions();
    }
    if ($exposed = $form_state->get('exposed')) {
        // Exposed filter: use a select box to save space.
        $filter_form_type = 'select';
    }
    else {
        // Configuring a filter: use radios for clarity.
        $filter_form_type = 'radios';
    }
    $form['value'] = [
        '#type' => $filter_form_type,
        '#title' => $this->value_value,
        '#options' => $this->valueOptions,
        '#default_value' => $this->value,
    ];
    if (!empty($this->options['exposed'])) {
        $identifier = $this->options['expose']['identifier'];
        $user_input = $form_state->getUserInput();
        if ($exposed && !isset($user_input[$identifier])) {
            $user_input[$identifier] = $this->value;
            $form_state->setUserInput($user_input);
        }
        // If we're configuring an exposed filter, add an - Any - option.
        if (!$exposed || empty($this->options['expose']['required'])) {
            $form['value']['#options'] = [
                'All' => $this->t('- Any -'),
            ] + $form['value']['#options'];
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.