From 7e152709974e356b7439bcff8b23925f74145d5f Mon Sep 17 00:00:00 2001 From: Karmalakas Date: Tue, 6 Jul 2021 21:14:06 +0300 Subject: [PATCH 1/2] Add `setCurrent()` method to Page Collection #531 --- system/src/Grav/Common/Page/Collection.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/system/src/Grav/Common/Page/Collection.php b/system/src/Grav/Common/Page/Collection.php index 139a58bc54..a37f46a273 100644 --- a/system/src/Grav/Common/Page/Collection.php +++ b/system/src/Grav/Common/Page/Collection.php @@ -145,6 +145,18 @@ public function intersect(PageCollectionInterface $collection) return $this; } + /** + * Set current page. + */ + public function setCurrent(string $path): void + { + reset($this->items); + + while (key($this->items) !== $path && key($this->items) !== null) { + next($this->items); + } + } + /** * Returns current page. * From c705f4f30977d39b2fd63463378913d8877d1b47 Mon Sep 17 00:00:00 2001 From: Karmalakas Date: Fri, 9 Jul 2021 00:29:54 +0300 Subject: [PATCH 2/2] Change key setting in a loop #531 --- system/src/Grav/Common/Page/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Collection.php b/system/src/Grav/Common/Page/Collection.php index a37f46a273..c9a3cdbd54 100644 --- a/system/src/Grav/Common/Page/Collection.php +++ b/system/src/Grav/Common/Page/Collection.php @@ -152,7 +152,7 @@ public function setCurrent(string $path): void { reset($this->items); - while (key($this->items) !== $path && key($this->items) !== null) { + while (($key = key($this->items)) !== null && $key !== $path) { next($this->items); } }