diff --git a/core/lib/Drupal/Core/Entity/Query/QueryBase.php b/core/lib/Drupal/Core/Entity/Query/QueryBase.php index f5805b6..1a15bed 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryBase.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php @@ -295,6 +295,11 @@ protected function initializePager() { global $pager_page_array; if ($this->pager && !empty($this->pager['limit']) && !$this->count) { + // Calculate the total number of results through a count query, to set + // the pager total. Then initialize the pager with the information at + // hand (total number of results, results per page, pager element id). + // The current page is available and validated from $pager_page_array + // after initialization. $count_query = clone $this; $this->pager['total'] = $count_query->count()->execute(); pager_default_initialize($this->pager['total'], $this->pager['limit'], $this->pager['element']); diff --git a/core/modules/system/src/Tests/Pager/PagerTest.php b/core/modules/system/src/Tests/Pager/PagerTest.php index 0de500b..06e5253 100644 --- a/core/modules/system/src/Tests/Pager/PagerTest.php +++ b/core/modules/system/src/Tests/Pager/PagerTest.php @@ -201,8 +201,8 @@ public function testEntityQueryPager() { // Try getting a page above the range, should render the last one. $this->drupalGet('pager-test/entity-query-pager', ['query' => ['page' => 200]]); + $this->assertNoText("There are no node ids found in the db"); $this->assertPagerItems(4); - } /**