function FilterPluginBase::acceptExposedInput

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

Determines if the input from a filter should change the generated query.

Parameters

array $input: The exposed data for this view.

Return value

bool TRUE if the input for this filter should be included in the view query. FALSE otherwise.

Overrides HandlerBase::acceptExposedInput

2 calls to FilterPluginBase::acceptExposedInput()
InOperator::acceptExposedInput in core/modules/views/src/Plugin/views/filter/InOperator.php
Determines if the input from a filter should change the generated query.
NumericFilter::acceptExposedInput in core/modules/views/src/Plugin/views/filter/NumericFilter.php
Do some minor translation of the exposed input.
2 methods override FilterPluginBase::acceptExposedInput()
InOperator::acceptExposedInput in core/modules/views/src/Plugin/views/filter/InOperator.php
Determines if the input from a filter should change the generated query.
NumericFilter::acceptExposedInput in core/modules/views/src/Plugin/views/filter/NumericFilter.php
Do some minor translation of the exposed input.

File

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

Class

FilterPluginBase
Base class for Views filters handler plugins.

Namespace

Drupal\views\Plugin\views\filter

Code

public function acceptExposedInput($input) {
    if (empty($this->options['exposed'])) {
        return TRUE;
    }
    if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id']) && isset($input[$this->options['expose']['operator_id']])) {
        $this->operator = $input[$this->options['expose']['operator_id']];
    }
    if (!empty($this->options['expose']['identifier'])) {
        if ($this->options['is_grouped']) {
            $value = $input[$this->options['group_info']['identifier']];
        }
        else {
            $value = $input[$this->options['expose']['identifier']];
        }
        // Various ways to check for the absence of non-required input.
        if (empty($this->options['expose']['required'])) {
            if (($this->operator == 'empty' || $this->operator == 'not empty') && $value === '') {
                $value = ' ';
            }
            if ($this->operator != 'empty' && $this->operator != 'not empty') {
                if ($value == 'All' || $value === 0 || $value === []) {
                    return FALSE;
                }
                // If checkboxes are used to render this filter, do not include the
                // filter if no options are checked.
                if (is_array($value) && Checkboxes::detectEmptyCheckboxes($value)) {
                    return FALSE;
                }
            }
            if (!empty($this->alwaysMultiple) && $value === '') {
                return FALSE;
            }
        }
        if (isset($value)) {
            $this->value = $value;
            if (empty($this->alwaysMultiple) && empty($this->options['expose']['multiple']) && !is_array($value)) {
                $this->value = [
                    $value,
                ];
            }
        }
        else {
            return FALSE;
        }
    }
    return TRUE;
}

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