mirror of
https://github.com/getgrav/grav.git
synced 2026-01-27 18:00:07 +01:00
Fixed page collection pagination not behaving as it did in Grav 1.6
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -2611,9 +2611,6 @@ class Page implements PageInterface
|
||||
}
|
||||
|
||||
$params['filter'] = ($params['filter'] ?? []) + ['translated' => true];
|
||||
if (!$pagination) {
|
||||
$params['pagination'] = false;
|
||||
}
|
||||
$context = [
|
||||
'pagination' => $pagination,
|
||||
'self' => $this
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user