class TableSortExtender
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Database/Query/TableSortExtender.php \Drupal\Core\Database\Query\TableSortExtender
- 10 core/tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFakeWithAllCustomClasses/TableSortExtender.php \Drupal\core_fake\Driver\Database\CoreFakeWithAllCustomClasses\TableSortExtender
- 10 core/lib/Drupal/Core/Database/Query/TableSortExtender.php \Drupal\Core\Database\Query\TableSortExtender
- 11.x core/tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFakeWithAllCustomClasses/TableSortExtender.php \Drupal\core_fake\Driver\Database\CoreFakeWithAllCustomClasses\TableSortExtender
- 11.x core/lib/Drupal/Core/Database/Query/TableSortExtender.php \Drupal\Core\Database\Query\TableSortExtender
Query extender class for tablesort queries.
Hierarchy
- class \Drupal\Core\Database\Query\SelectExtender implements \Drupal\Core\Database\Query\SelectInterface
- class \Drupal\Core\Database\Query\TableSortExtender extends \Drupal\Core\Database\Query\SelectExtender
Expanded class hierarchy of TableSortExtender
5 files declare their use of TableSortExtender
- DatabaseTestController.php in core/
modules/ system/ tests/ modules/ database_test/ src/ Controller/ DatabaseTestController.php - DatabaseTestForm.php in core/
modules/ system/ tests/ modules/ database_test/ src/ Form/ DatabaseTestForm.php - DbLogController.php in core/
modules/ dblog/ src/ Controller/ DbLogController.php - ForumManager.php in core/
modules/ forum/ src/ ForumManager.php - TableSortExtender.php in core/
tests/ fixtures/ database_drivers/ module/ corefake/ src/ Driver/ Database/ corefakeWithAllCustomClasses/ TableSortExtender.php
1 string reference to 'TableSortExtender'
- ConnectionTest::providerGetDriverClass in core/
tests/ Drupal/ Tests/ Core/ Database/ ConnectionTest.php - Data provider for testGetDriverClass().
File
-
core/
lib/ Drupal/ Core/ Database/ Query/ TableSortExtender.php, line 11
Namespace
Drupal\Core\Database\QueryView source
class TableSortExtender extends SelectExtender {
/**
* {@inheritdoc}
*/
public function __construct(SelectInterface $query, Connection $connection) {
parent::__construct($query, $connection);
// Add convenience tag to mark that this is an extended query. We have to
// do this in the constructor to ensure that it is set before preExecute()
// gets called.
$this->addTag('tablesort');
}
/**
* Order the query based on a header array.
*
* @param array $header
* Table header array.
*
* @return \Drupal\Core\Database\Query\SelectInterface
* The called object.
*
* @see table.html.twig
*/
public function orderByHeader(array $header) {
$context = TableSort::getContextFromRequest($header, \Drupal::request());
if (!empty($context['sql'])) {
// Based on code from \Drupal\Core\Database\Connection::escapeTable(),
// but this can also contain a dot.
$field = preg_replace('/[^A-Za-z0-9_.]+/', '', $context['sql']);
// orderBy() will ensure that only ASC/DESC values are accepted, so we
// don't need to sanitize that here.
$this->orderBy($field, $context['sort']);
}
return $this;
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.