You are here

function ViewsDependentFilter::get_filter_options in Views Dependent Filters 8

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 ViewsDependentFilter::get_filter_options()
ViewsDependentFilter::buildExtraOptionsForm in src/Plugin/views/filter/ViewsDependentFilter.php
Extra settings form: select the controller filter.
ViewsDependentFilter::buildOptionsForm in src/Plugin/views/filter/ViewsDependentFilter.php
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

src/Plugin/views/filter/ViewsDependentFilter.php, line 69

Class

ViewsDependentFilter
Filters by given list of related content title options.

Namespace

Drupal\views_dependent_filter\Plugin\views\filter

Code

function get_filter_options($type) {

  //kint($this);die();

  // 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
    ->getHandlers('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
      ->isExposed()) {
      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_filter') {
      continue;
    }

    //kint($handler);

    //$label = $handler->ui_name(TRUE);
    $label = $filter_id;

    // 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;
  }
}