You are here

public function ExposedFormPluginBase::query in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase::query()

Add anything to the query that we might need to.

Overrides PluginBase::query

1 call to ExposedFormPluginBase::query()
InputRequired::query in core/modules/views/src/Plugin/views/exposed_form/InputRequired.php
Add anything to the query that we might need to.
1 method overrides ExposedFormPluginBase::query()
InputRequired::query in core/modules/views/src/Plugin/views/exposed_form/InputRequired.php
Add anything to the query that we might need to.

File

core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php, line 162
Contains \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase.

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 = isset($view->exposed_data) ? $view->exposed_data : array();
  $sort_by = isset($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)
    if (isset($view->sort[$sort_by])) {
      $view->query->orderby = array();
      foreach ($view->sort as $key => $sort) {
        if (!$sort
          ->isExposed()) {
          $sort
            ->query();
        }
        elseif ($key == $sort_by) {
          if (isset($exposed_data['sort_order']) && in_array($exposed_data['sort_order'], array(
            'ASC',
            'DESC',
          ))) {
            $sort->options['order'] = $exposed_data['sort_order'];
          }
          $sort
            ->setRelationship();
          $sort
            ->query();
        }
      }
    }
  }
}