You are here

protected function WizardPluginBase::build_filters in Views (for Drupal 7) 8.3

Builds the form structure for selecting the view's filters.

By default, this adds "of type" and "tagged with" filters (when they are available).

2 calls to WizardPluginBase::build_filters()
Node::build_filters in lib/Views/node/Plugin/views/wizard/Node.php
Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::build_filters().
WizardPluginBase::build_form in lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php
Implements Drupal\views\Plugin\views\wizard\WizardInterface::build_form().
1 method overrides WizardPluginBase::build_filters()
Node::build_filters in lib/Views/node/Plugin/views/wizard/Node.php
Overrides Drupal\views\Plugin\views\wizard\WizardPluginBase::build_filters().

File

lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php, line 479
Definition of Drupal\views\Plugin\views\wizard\WizardPluginBase.

Class

WizardPluginBase
Provides the interface and base class for Views Wizard plugins.

Namespace

Drupal\views\Plugin\views\wizard

Code

protected function build_filters(&$form, &$form_state) {

  // Find all the fields we are allowed to filter by.
  $fields = views_fetch_fields($this->base_table, 'filter');
  $entity_info = $this->entity_info;

  // If the current base table support bundles and has more than one (like user).
  if (isset($entity_info['bundle keys']) && isset($entity_info['bundles'])) {

    // Get all bundles and their human readable names.
    $options = array(
      'all' => t('All'),
    );
    foreach ($entity_info['bundles'] as $type => $bundle) {
      $options[$type] = $bundle['label'];
    }
    $form['displays']['show']['type'] = array(
      '#type' => 'select',
      '#title' => t('of type'),
      '#options' => $options,
    );
    $selected_bundle = views_ui_get_selected($form_state, array(
      'show',
      'type',
    ), 'all', $form['displays']['show']['type']);
    $form['displays']['show']['type']['#default_value'] = $selected_bundle;

    // Changing this dropdown updates the entire content of $form['displays']
    // via AJAX, since each bundle might have entirely different fields
    // attached to it, etc.
    views_ui_add_ajax_trigger($form['displays']['show'], 'type', array(
      'displays',
    ));
  }
}