function FilterPluginBase::convertExposedInput

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

Transform the input from a grouped filter into a standard filter.

When a filter is a group, find the set of operator and values that the chosen item represents, and inform views that a normal filter was submitted by telling the operator and the value selected.

The param $selected_group_id is only passed when the filter uses the checkboxes widget, and this function will be called for each item chosen in the checkboxes.

File

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

Class

FilterPluginBase
Base class for Views filters handler plugins.

Namespace

Drupal\views\Plugin\views\filter

Code

public function convertExposedInput(&$input, $selected_group_id = NULL) {
    if ($this->isAGroup()) {
        // If it is already defined the selected group, use it. Only valid
        // when the filter uses checkboxes for widget.
        if (!empty($selected_group_id)) {
            $selected_group = $selected_group_id;
        }
        else {
            $selected_group = $input[$this->options['group_info']['identifier']];
        }
        if ($selected_group == 'All' && !empty($this->options['group_info']['optional'])) {
            return NULL;
        }
        if ($selected_group != 'All' && empty($this->options['group_info']['group_items'][$selected_group])) {
            return FALSE;
        }
        if (isset($selected_group) && isset($this->options['group_info']['group_items'][$selected_group])) {
            $selected_group_options = $this->options['group_info']['group_items'][$selected_group];
            $operator_id = $this->options['expose']['operator'];
            $input[$operator_id] = $selected_group_options['operator'];
            $this->options['expose']['operator_id'] = $operator_id;
            $this->options['expose']['use_operator'] = TRUE;
            // Value can be optional, For example for 'empty' and 'not empty' filters.
            if (isset($selected_group_options['value']) && $selected_group_options['value'] !== '') {
                $input[$this->options['group_info']['identifier']] = $selected_group_options['value'];
            }
            $this->group_info = $input[$this->options['group_info']['identifier']];
            return TRUE;
        }
        else {
            return FALSE;
        }
    }
}

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