You are here

public function FilterPluginBase::convertExposedInput in Drupal 8

Same name and namespace in other branches
  1. 9 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()

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 1329

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])) {
      $input[$this->options['expose']['operator']] = $this->options['group_info']['group_items'][$selected_group]['operator'];

      // Value can be optional, For example for 'empty' and 'not empty' filters.
      if (isset($this->options['group_info']['group_items'][$selected_group]['value']) && $this->options['group_info']['group_items'][$selected_group]['value'] !== '') {
        $input[$this->options['group_info']['identifier']] = $this->options['group_info']['group_items'][$selected_group]['value'];
      }
      $this->options['expose']['use_operator'] = TRUE;
      $this->group_info = $input[$this->options['group_info']['identifier']];
      return TRUE;
    }
    else {
      return FALSE;
    }
  }
}