diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 6bd5bf3da6..6f6da5c866 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -944,7 +944,7 @@ function template_preprocess_table(&$variables) { $ts = []; $header_columns = 0; if (!empty($variables['header'])) { - /** @var \Drupal\Core\Utility\TableSort $table_sort */ + /** @var \Drupal\Core\Utility\TableSortInterface $table_sort */ $table_sort = \Drupal::service('table_sort'); $ts = $table_sort->init($variables['header']); diff --git a/core/lib/Drupal/Core/Database/Query/TableSortExtender.php b/core/lib/Drupal/Core/Database/Query/TableSortExtender.php index df7d5af981..9c8b67e862 100644 --- a/core/lib/Drupal/Core/Database/Query/TableSortExtender.php +++ b/core/lib/Drupal/Core/Database/Query/TableSortExtender.php @@ -9,11 +9,6 @@ */ class TableSortExtender extends SelectExtender { - /** - * The array of fields that can be sorted by. - */ - protected $header = []; - /** * The table sorting service. * @@ -46,67 +41,17 @@ public function __construct(SelectInterface $query, Connection $connection) { * @see table.html.twig */ public function orderByHeader(array $header) { - $this->header = $header; - $ts = $this->init(); - if (!empty($ts['sql'])) { + $context = $this->tableSort->init($header); + 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_.]+/', '', $ts['sql']); + $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, $ts['sort']); + $this->orderBy($field, $context['sort']); } return $this; } - /** - * Initialize the table sort context. - */ - protected function init() { - $ts = $this->order(); - $ts['sort'] = $this->getSort(); - $ts['query'] = $this->getQueryParameters(); - return $ts; - } - - /** - * Determine the current sort direction. - * - * @return - * The current sort direction ("asc" or "desc"). - * - * @see \Drupal\Core\Utility\TableSortInterface::getSort() - */ - protected function getSort() { - return $this->tableSort->getSort($this->header); - } - - /** - * Compose a URL query parameter array to append to table sorting requests. - * - * @return - * A URL query parameter array that consists of all components of the current - * page request except for those pertaining to table sorting. - * - * @see \Drupal\Core\Utility\TableSortInterface::getQueryParameters() - */ - protected function getQueryParameters() { - return $this->tableSort->getQueryParameters(); - } - - /** - * Determine the current sort criterion. - * - * @return - * An associative array describing the criterion, containing the keys: - * - "name": The localized title of the table column. - * - "sql": The name of the database field to sort on. - * - * @see \Drupal\Core\Utility\TableSortInterface::getOrder() - */ - protected function order() { - return $this->tableSort->getOrder($this->header); - } - }