Loading core/lib/Drupal/Core/Pager/PagerManager.php +7 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,13 @@ public function getPager($element = 0) { return isset($this->pagers[$element]) ? $this->pagers[$element] : NULL; } /** * {@inheritdoc} */ public function findPage(int $pager_id = 0): int { return $this->pagerParams->findPage($pager_id); } /** * {@inheritdoc} */ Loading core/lib/Drupal/Core/Pager/PagerManagerInterface.php +20 −2 Original line number Diff line number Diff line Loading @@ -74,8 +74,8 @@ interface PagerManagerInterface { * // PagerManagerInterface::findPage(). This comes from a URL parameter, so * // here we are assuming that the URL parameter corresponds to an actual * // page of results that will exist within the set. * $pager_parameters = \Drupal::service('pager.parameters'); * $page = $pager_parameters->findPage(); * $pager_manager = \Drupal::service('pager.manager'); * $page = $pager_manager->findPage(); * $num_per_page = \Drupal::config('mymodule.settings')->get('num_per_page'); * $offset = $num_per_page * $page; * $result = mymodule_remote_search($keywords, $offset, $num_per_page); Loading Loading @@ -120,6 +120,24 @@ public function createPager($total, $limit, $element = 0); */ public function getPager($element = 0); /** * Returns the current page being requested for display within a pager. * * @param int $pager_id * (optional) An integer to distinguish between multiple pagers on one page. * * @return int * The number of the current requested page, within the pager represented by * $element. This is determined from the URL query parameter * \Drupal::request()->query->get('page'), or 0 by default. Note that this * number may differ from the actual page being displayed. For example, if a * search for "example text" brings up three pages of results, but a user * visits search/node/example+text?page=10, this function will return 10, * even though the default pager implementation adjusts for this and still * displays the third page of search results at that URL. */ public function findPage(int $pager_id = 0): int; /** * Gets the URL query parameter array of a pager link. * Loading core/tests/Drupal/KernelTests/Core/Pager/PagerManagerTest.php +15 −0 Original line number Diff line number Diff line Loading @@ -38,4 +38,19 @@ public function testGetUpdatedParameters() { $this->assertEquals(",,$index", $query['page']); } /** * @covers ::findPage */ public function testFindPage() { $request = Request::create('http://example.com', 'GET', ['page' => '0,10']); /* @var $request_stack \Symfony\Component\HttpFoundation\RequestStack */ $request_stack = $this->container->get('request_stack'); $request_stack->push($request); $pager_manager = $this->container->get('pager.manager'); $this->assertEquals(10, $pager_manager->findPage(1)); } } Loading
core/lib/Drupal/Core/Pager/PagerManager.php +7 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,13 @@ public function getPager($element = 0) { return isset($this->pagers[$element]) ? $this->pagers[$element] : NULL; } /** * {@inheritdoc} */ public function findPage(int $pager_id = 0): int { return $this->pagerParams->findPage($pager_id); } /** * {@inheritdoc} */ Loading
core/lib/Drupal/Core/Pager/PagerManagerInterface.php +20 −2 Original line number Diff line number Diff line Loading @@ -74,8 +74,8 @@ interface PagerManagerInterface { * // PagerManagerInterface::findPage(). This comes from a URL parameter, so * // here we are assuming that the URL parameter corresponds to an actual * // page of results that will exist within the set. * $pager_parameters = \Drupal::service('pager.parameters'); * $page = $pager_parameters->findPage(); * $pager_manager = \Drupal::service('pager.manager'); * $page = $pager_manager->findPage(); * $num_per_page = \Drupal::config('mymodule.settings')->get('num_per_page'); * $offset = $num_per_page * $page; * $result = mymodule_remote_search($keywords, $offset, $num_per_page); Loading Loading @@ -120,6 +120,24 @@ public function createPager($total, $limit, $element = 0); */ public function getPager($element = 0); /** * Returns the current page being requested for display within a pager. * * @param int $pager_id * (optional) An integer to distinguish between multiple pagers on one page. * * @return int * The number of the current requested page, within the pager represented by * $element. This is determined from the URL query parameter * \Drupal::request()->query->get('page'), or 0 by default. Note that this * number may differ from the actual page being displayed. For example, if a * search for "example text" brings up three pages of results, but a user * visits search/node/example+text?page=10, this function will return 10, * even though the default pager implementation adjusts for this and still * displays the third page of search results at that URL. */ public function findPage(int $pager_id = 0): int; /** * Gets the URL query parameter array of a pager link. * Loading
core/tests/Drupal/KernelTests/Core/Pager/PagerManagerTest.php +15 −0 Original line number Diff line number Diff line Loading @@ -38,4 +38,19 @@ public function testGetUpdatedParameters() { $this->assertEquals(",,$index", $query['page']); } /** * @covers ::findPage */ public function testFindPage() { $request = Request::create('http://example.com', 'GET', ['page' => '0,10']); /* @var $request_stack \Symfony\Component\HttpFoundation\RequestStack */ $request_stack = $this->container->get('request_stack'); $request_stack->push($request); $pager_manager = $this->container->get('pager.manager'); $this->assertEquals(10, $pager_manager->findPage(1)); } }