function ExposedFormPluginBase::query

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase::query()
  2. 8.9.x core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase::query()
  3. 10 core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase::query()

Overrides PluginBase::query

1 call to ExposedFormPluginBase::query()
InputRequired::query in core/modules/views/src/Plugin/views/exposed_form/InputRequired.php
1 method overrides ExposedFormPluginBase::query()
InputRequired::query in core/modules/views/src/Plugin/views/exposed_form/InputRequired.php

File

core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php, line 153

Class

ExposedFormPluginBase
Base class for Views exposed filter form plugins.

Namespace

Drupal\views\Plugin\views\exposed_form

Code

public function query() {
    $view = $this->view;
    $exposed_data = $view->exposed_data ?? [];
    $sort_by = $exposed_data['sort_by'] ?? NULL;
    if (!empty($sort_by)) {
        // Make sure the original order of sorts is preserved
        // (e.g. a sticky sort is often first)
        $view->query->orderby = [];
        foreach ($view->sort as $sort) {
            if (!$sort->isExposed()) {
                $sort->query();
            }
            elseif (!empty($sort->options['expose']['field_identifier']) && $sort->options['expose']['field_identifier'] === $sort_by) {
                if (isset($exposed_data['sort_order']) && in_array($exposed_data['sort_order'], [
                    'ASC',
                    'DESC',
                ], TRUE)) {
                    $sort->options['order'] = $exposed_data['sort_order'];
                }
                $sort->setRelationship();
                $sort->query();
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.