You are here

protected function WizardPluginBase::defaultDisplayFiltersUser in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php \Drupal\views\Plugin\views\wizard\WizardPluginBase::defaultDisplayFiltersUser()

Retrieves filter information based on user input for the default display.

Parameters

array $form: The full wizard form array.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the wizard form.

Return value

array An array of filter arrays keyed by ID. A sort array contains the options accepted by a filter handler.

2 calls to WizardPluginBase::defaultDisplayFiltersUser()
Node::defaultDisplayFiltersUser in core/modules/node/src/Plugin/views/wizard/Node.php
Retrieves filter information based on user input for the default display.
WizardPluginBase::defaultDisplayFilters in core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php
Retrieves all filter information used by the default display.
1 method overrides WizardPluginBase::defaultDisplayFiltersUser()
Node::defaultDisplayFiltersUser in core/modules/node/src/Plugin/views/wizard/Node.php
Retrieves filter information based on user input for the default display.

File

core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php, line 888
Contains \Drupal\views\Plugin\views\wizard\WizardPluginBase.

Class

WizardPluginBase
Base class for Views wizard plugins.

Namespace

Drupal\views\Plugin\views\wizard

Code

protected function defaultDisplayFiltersUser(array $form, FormStateInterface $form_state) {
  $filters = array();
  if (($type = $form_state
    ->getValue(array(
    'show',
    'type',
  ))) && $type != 'all') {
    $bundle_key = $this->entityType
      ->getKey('bundle');

    // Figure out the table where $bundle_key lives. It may not be the same as
    // the base table for the view; the taxonomy vocabulary machine_name, for
    // example, is stored in taxonomy_vocabulary, not taxonomy_term_data.
    module_load_include('inc', 'views_ui', 'admin');
    $fields = Views::viewsDataHelper()
      ->fetchFields($this->base_table, 'filter');
    if (isset($fields[$this->base_table . '.' . $bundle_key])) {
      $table = $this->base_table;
    }
    else {
      foreach ($fields as $field_name => $value) {
        if ($pos = strpos($field_name, '.' . $bundle_key)) {
          $table = substr($field_name, 0, $pos);
          break;
        }
      }
    }
    $table_data = Views::viewsData()
      ->get($table);

    // If the 'in' operator is being used, map the values to an array.
    $handler = $table_data[$bundle_key]['filter']['id'];
    $handler_definition = Views::pluginManager('filter')
      ->getDefinition($handler);
    if ($handler == 'in_operator' || is_subclass_of($handler_definition['class'], 'Drupal\\views\\Plugin\\views\\filter\\InOperator')) {
      $value = array(
        $type => $type,
      );
    }
    else {
      $value = $type;
    }
    $filters[$bundle_key] = array(
      'id' => $bundle_key,
      'table' => $table,
      'field' => $bundle_key,
      'value' => $value,
      'entity_type' => isset($table_data['table']['entity type']) ? $table_data['table']['entity type'] : NULL,
      'entity_field' => isset($table_data[$bundle_key]['entity field']) ? $table_data[$bundle_key]['entity field'] : NULL,
      'plugin_id' => $handler,
    );
  }
  return $filters;
}