diff --git a/core/lib/Drupal/Core/Entity/Query/QueryBase.php b/core/lib/Drupal/Core/Entity/Query/QueryBase.php index ed3d12b..f5805b6 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryBase.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php @@ -290,12 +290,15 @@ public function pager($limit = 10, $element = NULL) { * setting this query to be a count query. */ protected function initializePager() { + // @todo Remove global variable when https://www.drupal.org/node/2044435 is + // in. + global $pager_page_array; + if ($this->pager && !empty($this->pager['limit']) && !$this->count) { - $page = pager_find_page($this->pager['element']); $count_query = clone $this; $this->pager['total'] = $count_query->count()->execute(); - $this->pager['start'] = $page * $this->pager['limit']; pager_default_initialize($this->pager['total'], $this->pager['limit'], $this->pager['element']); + $this->pager['start'] = $pager_page_array[$this->pager['element']] * $this->pager['limit']; $this->range($this->pager['start'], $this->pager['limit']); } } diff --git a/core/modules/system/src/Tests/Pager/PagerTest.php b/core/modules/system/src/Tests/Pager/PagerTest.php index 71413f2..0a49a58 100644 --- a/core/modules/system/src/Tests/Pager/PagerTest.php +++ b/core/modules/system/src/Tests/Pager/PagerTest.php @@ -120,6 +120,13 @@ public function testMultiplePagers() { 'expected_page' => [0 => '3', 1 => '4', 4 => '5'], 'expected_query' => '?page=2,3,,,4', ], + // If negative values are passed as page numbers, the first page is + // returned. + [ + 'input_query' => '?page=-2,-6,,,5', + 'expected_page' => [0 => '1', 1 => '1', 4 => '6'], + 'expected_query' => '?page=0,0,,,5', + ], // If floats are passed as page numbers, only the integer part is // returned. [