function QueryBase::tableSort

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/Query/QueryBase.php \Drupal\Core\Entity\Query\QueryBase::tableSort()
  2. 10 core/lib/Drupal/Core/Entity/Query/QueryBase.php \Drupal\Core\Entity\Query\QueryBase::tableSort()
  3. 11.x core/lib/Drupal/Core/Entity/Query/QueryBase.php \Drupal\Core\Entity\Query\QueryBase::tableSort()

Overrides QueryInterface::tableSort

File

core/lib/Drupal/Core/Entity/Query/QueryBase.php, line 326

Class

QueryBase
The base entity query class.

Namespace

Drupal\Core\Entity\Query

Code

public function tableSort(&$headers) {
    // If 'field' is not initialized, the header columns aren't clickable.
    foreach ($headers as $key => $header) {
        if (is_array($header) && isset($header['specifier'])) {
            $headers[$key]['field'] = '';
        }
    }
    $order = TableSort::getOrder($headers, \Drupal::request());
    $direction = TableSort::getSort($headers, \Drupal::request());
    foreach ($headers as $header) {
        if (is_array($header) && $header['data'] == $order['name']) {
            $this->sort($header['specifier'], $direction, $header['langcode'] ?? NULL);
        }
    }
    return $this;
}

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