diff -u b/core/includes/tablesort.inc b/core/includes/tablesort.inc --- b/core/includes/tablesort.inc +++ b/core/includes/tablesort.inc @@ -21,7 +21,7 @@ * @see https://www.drupal.org/node/3009182 */ function tablesort_init($header) { - @trigger_error(__FUNCTION__ . ' is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call init() on it. For example, $table_sort->init($header). See https://www.drupal.org/node/3009182', E_USER_DEPRECATED); + @trigger_error(__FUNCTION__ . '() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call init() on it. For example, $table_sort->init($header). See https://www.drupal.org/node/3009182', E_USER_DEPRECATED); return \Drupal::service('table_sort')->init($header); } @@ -49,7 +49,7 @@ * @see https://www.drupal.org/node/3009182 */ function tablesort_header(&$cell_content, array &$cell_attributes, array $header, array $ts) { - @trigger_error(__FUNCTION__ . ' is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call header() on it. For example, $table_sort->header($cell_content, $cell_attributes, $header, $ts). See https://www.drupal.org/node/3009182', E_USER_DEPRECATED); + @trigger_error(__FUNCTION__ . '() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call header() on it. For example, $table_sort->header($cell_content, $cell_attributes, $header, $ts). See https://www.drupal.org/node/3009182', E_USER_DEPRECATED); \Drupal::service('table_sort')->header($cell_content, $cell_attributes, $header, $ts); } @@ -65,11 +65,11 @@ * container and call getQueryParameters() on it. For example, * $table_sort->getQueryParameters(); * - * @see \Drupal\Core\Utility\TableSortInterface::getQueryParameters() + * @see \Drupal\Core\Utility\TableSort::getQueryParameters() * @see https://www.drupal.org/node/3009182 */ function tablesort_get_query_parameters() { - @trigger_error(__FUNCTION__ . ' is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call getQueryParameters() on it. For example, $table_sort->getQueryParameters(). See https://www.drupal.org/node/3009182', E_USER_DEPRECATED); + @trigger_error(__FUNCTION__ . '() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call getQueryParameters() on it. For example, $table_sort->getQueryParameters(). See https://www.drupal.org/node/3009182', E_USER_DEPRECATED); return \Drupal::service('table_sort')->getQueryParameters(); } @@ -93,7 +93,7 @@ * @see https://www.drupal.org/node/3009182 */ function tablesort_get_order($headers) { - @trigger_error(__FUNCTION__ . ' is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call getOrder() on it. For example, $table_sort->getOrder($headers). See https://www.drupal.org/node/3009182', E_USER_DEPRECATED); + @trigger_error(__FUNCTION__ . '() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call getOrder() on it. For example, $table_sort->getOrder($headers). See https://www.drupal.org/node/3009182', E_USER_DEPRECATED); return \Drupal::service('table_sort')->getOrder($headers); } @@ -116,5 +116,5 @@ */ function tablesort_get_sort($headers) { - @trigger_error(__FUNCTION__ . ' is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call getSort() on it. For example, $table_sort->getSort($headers). See https://www.drupal.org/node/3009182', E_USER_DEPRECATED); + @trigger_error(__FUNCTION__ . '() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call getSort() on it. For example, $table_sort->getSort($headers). See https://www.drupal.org/node/3009182', E_USER_DEPRECATED); return \Drupal::service('table_sort')->getSort($headers); } diff -u b/core/lib/Drupal/Core/Utility/TableSort.php b/core/lib/Drupal/Core/Utility/TableSort.php --- b/core/lib/Drupal/Core/Utility/TableSort.php +++ b/core/lib/Drupal/Core/Utility/TableSort.php @@ -58,10 +58,7 @@ * The current request object. */ protected function request(Request $request = NULL) { - if ($request) { - return $request; - } - return $this->requestStack->getCurrentRequest(); + return $request ?: $this->requestStack->getCurrentRequest(); } /** @@ -116,13 +113,6 @@ /** * {@inheritdoc} */ - public function getQueryParameters(Request $request = NULL) { - return UrlHelper::filterQueryParameters($this->request($request)->query->all(), ['sort', 'order']); - } - - /** - * {@inheritdoc} - */ public function getOrder(array $headers, Request $request = NULL) { $order = $this->request($request)->query->get('order', ''); foreach ($headers as $header) { @@ -172,2 +162,16 @@ + /** + * Composes a URL query parameter array for table sorting links. + * + * @param \Symfony\Component\HttpFoundation\Request|null $request + * A current request (optional). + * + * @return array + * A URL query parameter array that consists of all components of the + * current page request except for those pertaining to table sorting. + */ + public function getQueryParameters(Request $request = NULL) { + return UrlHelper::filterQueryParameters($this->request($request)->query->all(), ['sort', 'order']); + } + } diff -u b/core/lib/Drupal/Core/Utility/TableSortInterface.php b/core/lib/Drupal/Core/Utility/TableSortInterface.php --- b/core/lib/Drupal/Core/Utility/TableSortInterface.php +++ b/core/lib/Drupal/Core/Utility/TableSortInterface.php @@ -48,18 +48,6 @@ public function header(&$cell_content, array &$cell_attributes, array $header, array $context); /** - * Composes a URL query parameter array for table sorting links. - * - * @param \Symfony\Component\HttpFoundation\Request|null $request - * A current request (optional). - * - * @return array - * A URL query parameter array that consists of all components of the - * current page request except for those pertaining to table sorting. - */ - public function getQueryParameters(Request $request = NULL); - - /** * Determines the current sort criterion. * * @param array $headers only in patch2: unchanged: --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Theme/TableSortLegacyTest.php @@ -0,0 +1,75 @@ +init($header). See https://www.drupal.org/node/3009182 + */ + public function testInit() { + $context = tablesort_init([]); + $this->assertArrayHasKey('query', $context); + $this->assertArrayHasKey('sort', $context); + } + + /** + * Tests deprecation of the tablesort_header() function. + * + * @expectedDeprecation tablesort_header() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call header() on it. For example, $table_sort->header($cell_content, $cell_attributes, $header, $ts). See https://www.drupal.org/node/3009182 + */ + public function testHeader() { + $cell_content = ''; + $cell_attributes = []; + tablesort_header($cell_content, $cell_attributes, [], []); + $this->assertEquals('', $cell_content); + } + + /** + * Tests deprecation of the tablesort_get_query_parameters() function. + * + * @expectedDeprecation tablesort_get_query_parameters() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call getQueryParameters() on it. For example, $table_sort->getQueryParameters(). See https://www.drupal.org/node/3009182 + */ + public function testQueryParameters() { + $parameters = tablesort_get_query_parameters(); + $this->assertArrayNotHasKey('sort', $parameters); + $this->assertArrayNotHasKey('order', $parameters); + } + + /** + * Tests deprecation of the tablesort_get_order() function. + * + * @expectedDeprecation tablesort_get_order() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call getOrder() on it. For example, $table_sort->getOrder($headers). See https://www.drupal.org/node/3009182 + */ + public function testOrder() { + $this->assertEquals( + [ + 'name' => NULL, + 'sql' => NULL, + ], + tablesort_get_order([]) + ); + } + + /** + * Tests deprecation of the tablesort_get_sort() function. + * + * @expectedDeprecation tablesort_get_sort() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Instead, get a TableSort utility injected into your service from the container and call getSort() on it. For example, $table_sort->getSort($headers). See https://www.drupal.org/node/3009182 + */ + public function testSort() { + $this->assertEquals(TableSortInterface::ASC, tablesort_get_sort([])); + } + +}