function InOperator::reduceValueOptions

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

When using exposed filters, we may be required to reduce the set.

2 calls to InOperator::reduceValueOptions()
InOperator::valueForm in core/modules/views/src/Plugin/views/filter/InOperator.php
TaxonomyIndexTid::valueForm in core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php

File

core/modules/views/src/Plugin/views/filter/InOperator.php, line 261

Class

InOperator
Simple filter to handle matching of multiple options selectable via checkboxes.

Namespace

Drupal\views\Plugin\views\filter

Code

public function reduceValueOptions($input = NULL) {
    if (!isset($input)) {
        $input = $this->valueOptions;
    }
    // Because options may be an array of strings, or an array of mixed arrays
    // and strings (optgroups), or an array of objects, or a form of Markup, we
    // have to step through and handle each one individually.
    $options = [];
    foreach ($input as $id => $option) {
        if (is_array($option)) {
            $options[$id] = $this->reduceValueOptions($option);
            continue;
        }
        elseif (is_object($option) && !$option instanceof MarkupInterface) {
            $keys = array_keys($option->option);
            $key = array_shift($keys);
            if (isset($this->options['value'][$key])) {
                $options[$id] = $option;
            }
        }
        elseif (isset($this->options['value'][$id])) {
            $options[$id] = $option;
        }
    }
    return $options;
}

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