diff --git a/CHANGELOG.md b/CHANGELOG.md index ec81e259a..55ffb0bea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ * Set `cache.clear_images_by_default` to `false` by default 1. [](#bugfix) * Improve Plugin and Theme initialization to fix PHP8 bug [#3368](https://github.com/getgrav/grav/issues/3368) - * Fixed `pathinfo()` twig filter in PHP 7 + * Fixed `pathinfo()` twig filter in PHP7 + * Fixed the first visible child page getting ordering number `999999.` [#3365](https://github.com/getgrav/grav/issues/3365) # v1.7.15 ## 05/19/2021 diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php index 933a00a32..b1ec6bfa3 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php @@ -367,7 +367,7 @@ class PageObject extends FlexPageObject $filesystem = Filesystem::getInstance(false); $oldParentKey = ltrim($filesystem->dirname("/{$storageKey}"), '/'); $newParentKey = $this->getProperty('parent_key'); - $isMoved = $oldParentKey !== $newParentKey; + $isMoved = $this->exists() && $oldParentKey !== $newParentKey; $order = !$isMoved ? $this->order() : false; if ($order !== false) { $order = (int)$order; @@ -385,10 +385,12 @@ class PageObject extends FlexPageObject // Handle special case where ordering isn't given. if ($ordering === []) { if ($order >= 999999) { - // Set ordering to point to be the last item. + // Set ordering to point to be the last item, ignoring the object itself. $order = 0; foreach ($siblings as $sibling) { - $order = max($order, (int)$sibling->order()); + if ($sibling->getKey() !== $this->getKey()) { + $order = max($order, (int)$sibling->order()); + } } $this->order($order + 1); }