You are here

protected function Node::defaultDisplayFiltersUser in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Plugin/views/wizard/Node.php \Drupal\node\Plugin\views\wizard\Node::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.

Overrides WizardPluginBase::defaultDisplayFiltersUser

File

core/modules/node/src/Plugin/views/wizard/Node.php, line 115
Contains \Drupal\node\Plugin\views\wizard\Node.

Class

Node
Tests creating node views with the wizard.

Namespace

Drupal\node\Plugin\views\wizard

Code

protected function defaultDisplayFiltersUser(array $form, FormStateInterface $form_state) {
  $filters = parent::defaultDisplayFiltersUser($form, $form_state);
  $tids = array();
  if ($values = $form_state
    ->getValue(array(
    'show',
    'tagged_with',
  ))) {
    foreach ($values as $value) {
      $tids[] = $value['target_id'];
    }
  }
  if (!empty($tids)) {
    $vid = reset($form['displays']['show']['tagged_with']['#selection_settings']['target_bundles']);
    $filters['tid'] = array(
      'id' => 'tid',
      'table' => 'taxonomy_index',
      'field' => 'tid',
      'value' => $tids,
      'vid' => $vid,
      'plugin_id' => 'taxonomy_index_tid',
    );

    // If the user entered more than one valid term in the autocomplete
    // field, they probably intended both of them to be applied.
    if (count($tids) > 1) {
      $filters['tid']['operator'] = 'and';

      // Sort the terms so the filter will be displayed as it normally would
      // on the edit screen.
      sort($filters['tid']['value']);
    }
  }
  return $filters;
}