You are here

function views_dependent_filters_handler_filter_dependent::get_filter_options in Views Dependent Filters 7

Helper function to provide form options for lists of filters.

Parameters

$type: One of 'controller' or 'dependent'.

Return value

An array of filters suitable for use as Form API options.

2 calls to views_dependent_filters_handler_filter_dependent::get_filter_options()
views_dependent_filters_handler_filter_dependent::extra_options_form in ./views_dependent_filters_handler_filter_dependent.inc
Extra settings form: select the controller filter.
views_dependent_filters_handler_filter_dependent::options_form in ./views_dependent_filters_handler_filter_dependent.inc
Provide the basic form which calls through to subforms. If overridden, it is best to call through to the parent, or to at least make sure all of the functions in this form are called.

File

./views_dependent_filters_handler_filter_dependent.inc, line 56

Class

views_dependent_filters_handler_filter_dependent

Code

function get_filter_options($type) {

  // Due to http://drupal.org/node/1426094 we can't just go looking in the
  // handlers array on the display.
  $filters = $this->view->display_handler
    ->get_handlers('filter');

  // Get the unique id of this handler (ie allow more than one of this handler).
  $this_id = $this->options['id'];
  $filters_controller = array();
  $filters_dependent = array();
  $seen = FALSE;

  // Build up the options from all the fields up to this one but no further.
  foreach ($filters as $filter_id => $handler) {

    // Skip non-exposed filters.
    if (!$handler
      ->is_exposed()) {
      continue;
    }

    // Required filters can't be dependent.
    if ($type == 'dependent' && $handler->options['expose']['required']) {
      continue;
    }

    // Note if we get to ourselves and skip.
    if ($filter_id == $this_id) {
      $seen = TRUE;
      continue;
    }

    // Skip other instances of this filter.
    if ($handler->definition['handler'] == 'views_dependent_filters_handler_filter_dependent') {
      continue;
    }
    $label = $handler
      ->ui_name(TRUE);

    // All filters may be controllers, but to simplify things we just allow
    // the ones that come before us.
    if (!$seen) {
      $filters_controller[$filter_id] = $label;
    }

    // Only filters that follow us in the order may be dependent.
    if ($seen) {
      $filters_dependent[$filter_id] = $label;
    }
  }
  switch ($type) {
    case 'controller':
      return $filters_controller;
    case 'dependent':
      return $filters_dependent;
  }
}