From b9a569b71f8a058142bcb23d4ba4cd22ab2c624d Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 8 Dec 2014 15:30:29 -0700 Subject: [PATCH] Fix for prevSibling/nextSibling/isFirst/isLast when limit is imposed on parent collection --- system/src/Grav/Common/Page/Page.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 862b1f6e6..798034aa2 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -1186,7 +1186,7 @@ class Page */ public function isFirst() { - $collection = $this->parent()->collection(); + $collection = $this->parent()->collection('content', false); return $collection->isFirst($this->path()); } @@ -1197,7 +1197,7 @@ class Page */ public function isLast() { - $collection = $this->parent()->collection(); + $collection = $this->parent()->collection('content', false); return $collection->isLast($this->path()); } @@ -1229,7 +1229,7 @@ class Page */ public function adjacentSibling($direction = 1) { - $collection = $this->parent()->collection(); + $collection = $this->parent()->collection('content', false); return $collection->adjacentSibling($this->path(), $direction); } @@ -1318,10 +1318,11 @@ class Page * Get a collection of pages in the current context. * * @param string|array $params + * @param boolean $pagination * @return Collection * @throws \InvalidArgumentException */ - public function collection($params = 'content') + public function collection($params = 'content', $pagination = true) { if (is_string($params)) { $params = (array) $this->value('header.'.$params); @@ -1378,13 +1379,16 @@ class Page // New Custom event to handle things like pagination. $grav->fireEvent('onCollectionProcessed', new Event(['collection' => $collection])); - $params = $collection->params(); + // Slice and dice the collection if pagination is required + if ($pagination) { + $params = $collection->params(); - $limit = isset($params['limit']) ? $params['limit'] : 0; - $start = !empty($params['pagination']) ? ($uri->currentPage() - 1) * $limit : 0; + $limit = isset($params['limit']) ? $params['limit'] : 0; + $start = !empty($params['pagination']) ? ($uri->currentPage() - 1) * $limit : 0; - if ($limit && $collection->count() > $limit) { - $collection->slice($start, $limit); + if ($limit && $collection->count() > $limit) { + $collection->slice($start, $limit); + } } return $collection;