You are here

protected static function Selective::filterOriginalOptions in Views Selective Filters 8

Filters a list of original options according to selected set.

Parameters

array $options: The options list of the original filter.

array $set: The narrowed set of results provided by the cloned view.

Return value

array The original filter options list narrowed to the cloned query results.

1 call to Selective::filterOriginalOptions()
Selective::getOids in src/Plugin/views/filter/Selective.php
Returns a list of options for current view, only at runtime.

File

src/Plugin/views/filter/Selective.php, line 431

Class

Selective
Views filter handler for selective values.

Namespace

Drupal\views_selective_filters\Plugin\views\filter

Code

protected static function filterOriginalOptions(array $options, array $set) {
  $filtered = [];
  foreach ($options as $key => $value) {

    // Handle grouped options.
    // @see hook_options_list().
    if (is_array($value)) {
      $nested = static::filterOriginalOptions($value, $set);
      if (!empty($nested)) {
        $filtered[$key] = $nested;
      }
      continue;
    }
    if (in_array($key, $set)) {
      $filtered[$key] = $value;
    }
  }
  return $filtered;
}