You are here

function _views_filters_selective_reduce_options in Views Hacks 6

Helper function to reduce #options arrays (that can contain arrays or objects).

Parameters

$options: an options array, that can be passed to FAPI #options

$keys: array of keys of the options array to reduce to.

Return value

array of options for select & co, see FAPI #options.

See also

form_select_options()

1 call to _views_filters_selective_reduce_options()
views_filters_selective_form_views_exposed_form_alter_do in views_filters_selective/views_filters_selective.module

File

views_filters_selective/views_filters_selective.module, line 382

Code

function _views_filters_selective_reduce_options($options, $keys) {
  $return_options = array();
  foreach ($options as $id => $option) {

    // option is an optgroup, so check the optgroup children
    if (is_array($option)) {
      $result = _views_filters_selective_reduce_options($option, $keys);
      if (!empty($result)) {
        $return_options[$id] = $result;
      }
    }
    elseif (is_object($option)) {
      $result = _views_filters_selective_reduce_options($option->option, $keys);
      if (!empty($result)) {
        $option->option = $result;
        $return_options[$id] = $option;
      }
    }
    elseif (in_array($id, $keys)) {
      $return_options[$id] = $option;
    }
  }
  return $return_options;
}