function BooleanOperator::valueForm

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/filter/BooleanOperator.php \Drupal\views\Plugin\views\filter\BooleanOperator::valueForm()
  2. 8.9.x 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()

Options form subform for setting options.

This should be overridden by all child classes and it must define $form['value']

Parameters

array $form: An alterable, associative array containing the structure of the form, passed by reference.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FilterPluginBase::valueForm

File

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

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.