diff --git a/core/globals.api.php b/core/globals.api.php index 0f846e6..24cb752 100644 --- a/core/globals.api.php +++ b/core/globals.api.php @@ -83,8 +83,8 @@ * provided by \Drupal\Core\Pager\PagerFactoryInterface and * \Drupal\Core\Pager\PagerInterface instead. * + * @see \Drupal\Core\Pager\PagerFactoryInterface::set() * @see \Drupal\Core\Pager\PagerFactoryInterface::get() - * @see \Drupal\Core\Pager\PagerInterface::init() * @see \Drupal\Core\Pager\PagerInterface::getLimit() */ global $pager_limits; @@ -99,8 +99,8 @@ * provided by \Drupal\Core\Pager\PagerFactoryInterface and * \Drupal\Core\Pager\PagerInterface instead. * + * @see \Drupal\Core\Pager\PagerFactoryInterface::set() * @see \Drupal\Core\Pager\PagerFactoryInterface::get() - * @see \Drupal\Core\Pager\PagerInterface::init() * @see \Drupal\Core\Pager\PagerInterface::getCurrentPage() */ global $pager_page_array; @@ -115,8 +115,8 @@ * provided by \Drupal\Core\Pager\PagerFactoryInterface and * \Drupal\Core\Pager\PagerInterface instead. * + * @see \Drupal\Core\Pager\PagerFactoryInterface::set() * @see \Drupal\Core\Pager\PagerFactoryInterface::get() - * @see \Drupal\Core\Pager\PagerInterface::init() * @see \Drupal\Core\Pager\PagerInterface::getTotalPages() */ global $pager_total; @@ -131,8 +131,8 @@ * provided by \Drupal\Core\Pager\PagerFactoryInterface and * \Drupal\Core\Pager\PagerInterface instead. * + * @see \Drupal\Core\Pager\PagerFactoryInterface::set() * @see \Drupal\Core\Pager\PagerFactoryInterface::get() - * @see \Drupal\Core\Pager\PagerInterface::init() * @see \Drupal\Core\Pager\PagerInterface::getTotalItems() */ global $pager_total_items; diff --git a/core/includes/pager.inc b/core/includes/pager.inc index 42ea60c..8925f04 100644 --- a/core/includes/pager.inc +++ b/core/includes/pager.inc @@ -139,14 +139,14 @@ function pager_default_initialize($total, $limit, $element = 0) { * page request except for those pertaining to paging. * * @deprecated as of Drupal 8.3.x, will be removed before Drupal 9.0.0. - * Use - * \Drupal::service('pager.factory')->getCurrentRequestQueryParameters(['page']) - * instead. + * Use \Drupal::service('pager.factory')->getQueryParameters() instead. */ function pager_get_query_parameters() { - $pager_factory = \Drupal::service('pager.factory'); - $pager_parameter = $pager_factory->getPagerParameterName(); - return $pager_factory->getCurrentRequestQueryParameters([$pager_parameter]); + $query = &drupal_static(__FUNCTION__); + if (!isset($query)) { + $query = \Drupal::service('pager.factory')->getQueryParameters(); + } + return $query; } /** @@ -300,7 +300,7 @@ function template_preprocess_pager(&$variables) { * Use * \Drupal::service('pager.factory')->get($element)->getLinkQueryParameters($index, $query) * instead. However, normally this function should no longer be called, the - * the PagerInterface object can return a full URL link via + * PagerInterface object can return a full URL link via * PagerInterface::toUrl(). * * @see \Drupal\Core\Pager\PagerInterface diff --git a/core/lib/Drupal/Core/Pager/Pager.php b/core/lib/Drupal/Core/Pager/Pager.php index 3b86757..4711b26 100644 --- a/core/lib/Drupal/Core/Pager/Pager.php +++ b/core/lib/Drupal/Core/Pager/Pager.php @@ -12,9 +12,9 @@ class Pager implements PagerInterface { /** * The pager element. * - * This is the index used by query extenders to identify the query - * to be paged, and reflected in the 'page=x,y,z' query parameter - * of the HTTP request. + * This is the index used by query extenders to identify the query to be + * paged, and reflected in the 'page=x,y,z' query parameter of the HTTP + * request. * * @var int */ @@ -213,9 +213,9 @@ public function getLinkQueryParameters($page, array $query_parameters) { $query[$parameter] = implode(',', $element_pages); // Merge the query parameters passed to this function with the parameters - // from the current request. In case of collision, the parameters passed into - // this function take precedence. - if ($current_request_query = $this->factory->getCurrentRequestQueryParameters()) { + // from the current request. In case of collision, the parameters passed + // into this function take precedence. + if ($current_request_query = $this->factory->getQueryParameters()) { $query = array_merge($current_request_query, $query); } diff --git a/core/lib/Drupal/Core/Pager/PagerFactory.php b/core/lib/Drupal/Core/Pager/PagerFactory.php index fd16ff1..2059fa6 100644 --- a/core/lib/Drupal/Core/Pager/PagerFactory.php +++ b/core/lib/Drupal/Core/Pager/PagerFactory.php @@ -122,24 +122,11 @@ protected function getCurrentRequestQuery() { /** * {@inheritdoc} */ - public function getCurrentRequestQueryParameter($parameter) { - return $this->getCurrentRequestQuery()->get($parameter, ''); - } - - /** - * {@inheritdoc} - */ - public function getCurrentRequestQueryParameters(array $filter = []) { - // @todo: BC layer. In Drupal 9.0.0, remove the $filter argument and just - // return the current request query. - if (!$filter) { - return $this->getCurrentRequestQuery()->all(); - } - static $query, $filtered; - if (!isset($query) || $filter !== $filtered) { - $parameter = $this->getPagerParameterName(); - $query = UrlHelper::filterQueryParameters($this->getCurrentRequestQuery()->all(), [$parameter]); - $filtered = $filter; + public function getQueryParameters() { + static $query; + if (!isset($query)) { + $pager_parameter = $this->getPagerParameterName(); + $query = UrlHelper::filterQueryParameters($this->getCurrentRequestQuery()->all(), [$pager_parameter]); } return $query; } @@ -148,7 +135,7 @@ public function getCurrentRequestQueryParameters(array $filter = []) { * {@inheritdoc} */ public function findCurrentPage($element) { - $page_query = $this->getCurrentRequestQueryParameter($this->getPagerParameterName()); + $page_query = $this->getCurrentRequestQuery()->get($this->getPagerParameterName()); $page_array = explode(',', $page_query); if (!isset($page_array[$element])) { $page_array[$element] = 0; diff --git a/core/lib/Drupal/Core/Pager/PagerFactoryInterface.php b/core/lib/Drupal/Core/Pager/PagerFactoryInterface.php index b2c8d31..602eb96 100644 --- a/core/lib/Drupal/Core/Pager/PagerFactoryInterface.php +++ b/core/lib/Drupal/Core/Pager/PagerFactoryInterface.php @@ -65,32 +65,6 @@ public function all(); public function getPagerParameterName(); /** - * Returns a query string parameter from the current request. - * - * @param string $parameter - * The query string parameter to return, e.g. 'page'. - * - * @return string[] - * The requested query parameter. - */ - public function getCurrentRequestQueryParameter($parameter); - - /** - * Returns the current request query string, with optional filtering. - * - * @param array $filter - * An array of query string parameters to remove from the returned query - * parameters, e.g. ['page']. Defaults to empty array. - * - * @todo: BC layer. In Drupal 9.0.0, remove the $filter argument. - * - * @return array - * A URL query parameter array that consists of all components of the current - * page request except for those filtered out. - */ - public function getCurrentRequestQueryParameters(array $filter = []); - - /** * Finds the current page, from the request query parameters. * * @param int $element @@ -101,4 +75,13 @@ public function getCurrentRequestQueryParameters(array $filter = []); */ public function findCurrentPage($element); + /** + * Returns the URL query parameter array for pager links. + * + * @return array + * A URL query parameter array that consists of all components of the + * current page request except for those pertaining to paging. + */ + public function getQueryParameters(); + } diff --git a/core/tests/Drupal/Tests/Core/Pager/PagerFactoryTest.php b/core/tests/Drupal/Tests/Core/Pager/PagerFactoryTest.php index 42fcba7..e233e08 100644 --- a/core/tests/Drupal/Tests/Core/Pager/PagerFactoryTest.php +++ b/core/tests/Drupal/Tests/Core/Pager/PagerFactoryTest.php @@ -3,9 +3,7 @@ namespace Drupal\Tests\Core\Pager; use Drupal\Tests\UnitTestCase; -use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Pager\PagerFactory; -use Drupal\Core\Pager\Pager; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\ParameterBag; @@ -116,21 +114,10 @@ public function testGetPagerParameterName() { } /** - * @covers ::getCurrentRequestQueryParameters + * @covers ::getQueryParameters */ - public function testGetCurrentRequestQueryParameters() { - $this->assertSame(['page' => '10,15', 'foo' => 'bar', 'qux' => 'dee'], $this->pagerFactory->getCurrentRequestQueryParameters()); - } - - /** - * @covers ::getCurrentRequestQueryParameter - */ - public function testGetCurrentRequestQueryParameter() { - $this->assertSame('10,15', $this->pagerFactory->getCurrentRequestQueryParameter('page')); - $this->assertSame('bar', $this->pagerFactory->getCurrentRequestQueryParameter('foo')); - $this->assertSame('dee', $this->pagerFactory->getCurrentRequestQueryParameter('qux')); - // Missing parameter returns empty string. - $this->assertSame('', $this->pagerFactory->getCurrentRequestQueryParameter('zot')); + public function testGetQueryParameters() { + $this->assertSame(['foo' => 'bar', 'qux' => 'dee'], $this->pagerFactory->getQueryParameters()); } /** diff --git a/core/tests/Drupal/Tests/Core/Pager/PagerTest.php b/core/tests/Drupal/Tests/Core/Pager/PagerTest.php index 3dd2403..7ac5d07 100644 --- a/core/tests/Drupal/Tests/Core/Pager/PagerTest.php +++ b/core/tests/Drupal/Tests/Core/Pager/PagerTest.php @@ -3,11 +3,8 @@ namespace Drupal\Tests\Core\Pager; use Drupal\Tests\UnitTestCase; -use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Pager\PagerFactory; use Drupal\Core\Pager\Pager; -use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpFoundation\ParameterBag; /** * Tests the Pager class. @@ -43,15 +40,11 @@ protected function setUp() { ->will($this->returnValue('page')); // Set page query parameter current page to 11 (0-indexed). $pager_factory->expects($this->any()) - ->method('getCurrentRequestQueryParameter') - ->will($this->returnValue(',,,,,,11')); - // Set page query parameter current page to 11 (0-indexed). - $pager_factory->expects($this->any()) ->method('findCurrentPage') ->will($this->returnValue(11)); // Set other dummy query parameters. $pager_factory->expects($this->any()) - ->method('getCurrentRequestQueryParameters') + ->method('getQueryParameters') ->will($this->returnValue(['rec' => 'lop', 'ste' => 'cik'])); // Pager for element 6.