diff --git a/CHANGELOG.md b/CHANGELOG.md index b35618bf1..c6e2985f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ * Fixed page collections containing dummy items for untranslated default language [#2985](https://github.com/getgrav/grav/issues/2985) * Fixed streams in `setup.php` being overridden by `system/streams.yaml` [#2450](https://github.com/getgrav/grav/issues/2450) * Fixed `ERR_TOO_MANY_REDIRECTS` with HTTPS = 'On' [#3155](https://github.com/getgrav/grav/issues/3155) + * Fixed page collection pagination not behaving as it did in Grav 1.6 # v1.7.0-rc.20 ## 12/15/2020 diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 9f85bd8c6..4ec5f4a21 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -2611,9 +2611,6 @@ class Page implements PageInterface } $params['filter'] = ($params['filter'] ?? []) + ['translated' => true]; - if (!$pagination) { - $params['pagination'] = false; - } $context = [ 'pagination' => $pagination, 'self' => $this diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 5e2a069a1..d6f9d5eea 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -422,10 +422,10 @@ class Pages } $pagination = $params['pagination'] ?? $context['pagination']; - if ($pagination && !isset($params['page'])) { + if ($pagination && !isset($params['page'], $params['start'])) { /** @var Uri $uri */ $uri = $this->grav['uri']; - $context['pagination_page'] = $uri->currentPage(); + $context['current_page'] = $uri->currentPage(); } $collection = $this->evaluate($params['items'], $context['self']); @@ -545,18 +545,20 @@ class Pages // New Custom event to handle things like pagination. if ($context['event']) { - $this->grav->fireEvent('onCollectionProcessed', new Event(['collection' => $collection])); + $this->grav->fireEvent('onCollectionProcessed', new Event(['collection' => $collection, 'context' => $context])); } - // Slice and dice the collection if pagination is required - if ($pagination) { + if ($context['pagination']) { + // Slice and dice the collection if pagination is required $params = $collection->params(); $limit = (int)($params['limit'] ?? 0); - $start = !empty($params['pagination']) ? (($params['page'] ?? $context['pagination_page']) - 1) * $limit : 0; + $page = (int)($params['page'] ?? $context['current_page'] ?? 0); + $start = (int)($params['start'] ?? 0); + $start = $limit > 0 && $page > 0 ? ($page - 1) * $limit : max(0, $start); - if ($limit && $collection->count() > $limit) { - $collection->slice($start, $limit); + if ($start || ($limit && $collection->count() > $limit)) { + $collection->slice($start, $limit ?: null); } }