Skip to content

Commit

Permalink
Fixed the first visible child page getting ordering number 999999. [#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed May 26, 2021
1 parent 7f23b08 commit 33be694
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions system/src/Grav/Common/Flex/Types/Pages/PageObject.php
Expand Up @@ -367,7 +367,7 @@ protected function reorderSiblings(array $ordering)
$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;
Expand All @@ -385,10 +385,12 @@ protected function reorderSiblings(array $ordering)
// 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);
}
Expand Down

0 comments on commit 33be694

Please sign in to comment.