function FilterPluginBase::buildExposedForm

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

Render our chunk of the exposed filter form when selecting

You can override this if it doesn't do what you expect.

Overrides HandlerBase::buildExposedForm

File

core/modules/views/src/Plugin/views/filter/FilterPluginBase.php, line 894

Class

FilterPluginBase
Base class for Views filters handler plugins.

Namespace

Drupal\views\Plugin\views\filter

Code

public function buildExposedForm(&$form, FormStateInterface $form_state) {
    if (empty($this->options['exposed'])) {
        return;
    }
    // Build the exposed form, when its based on an operator.
    if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id'])) {
        $operator = $this->options['expose']['operator_id'];
        $this->operatorForm($form, $form_state);
        // Limit the exposed operators if needed.
        if (!empty($this->options['expose']['operator_limit_selection']) && !empty($this->options['expose']['operator_list'])) {
            $options = $this->operatorOptions();
            $operator_list = $this->options['expose']['operator_list'];
            $form['operator']['#options'] = array_intersect_key($options, $operator_list);
        }
        $form[$operator] = $form['operator'];
        $this->exposedTranslate($form[$operator], 'operator');
        unset($form['operator']);
    }
    // Build the form and set the value based on the identifier.
    if (!empty($this->options['expose']['identifier'])) {
        $value = $this->options['expose']['identifier'];
        $this->valueForm($form, $form_state);
        $form[$value] = $form['value'];
        if (isset($form[$value]['#title']) && !empty($form[$value]['#type']) && $form[$value]['#type'] != 'checkbox') {
            unset($form[$value]['#title']);
        }
        $this->exposedTranslate($form[$value], 'value');
        if ($value != 'value') {
            unset($form['value']);
        }
    }
}

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