Flex Pages: Fixed fatal error when trying to move a page to Root (/) [#3161]

This commit is contained in:
Matias Griese
2021-01-20 12:24:40 +02:00
parent 6992d52767
commit eb98597220
2 changed files with 9 additions and 1 deletions

View File

@@ -6,6 +6,7 @@
* Sanitize valid Page extensions from `Page::template_format()`
* Fixed `bin/gpm index` erroring out [#3158](https://github.com/getgrav/grav/issues/3158)
* Fixed `bin/gpm selfupgrade` failing to report failed Grav update [#3116](https://github.com/getgrav/grav/issues/3116)
* Flex Pages: Fixed fatal error when trying to move a page to Root (/) [#3161](https://github.com/getgrav/grav/issues/3161)
# v1.7.0
## 01/19/2021

View File

@@ -372,7 +372,14 @@ class PageObject extends FlexPageObject
// If menu item was moved, just make it to be the last in order.
if ($isMoved && $this->order() !== false) {
$parentKey = $this->getProperty('parent_key');
$newParent = $this->getFlexDirectory()->getObject($parentKey, 'storage_key');
if ($parentKey === '') {
$newParent = $this->getFlexDirectory()->getIndex()->getRoot();
} else {
$newParent = $this->getFlexDirectory()->getObject($parentKey, 'storage_key');
if (!$newParent instanceof PageInterface) {
throw new RuntimeException("New parent page '{$parentKey}' not found.");
}
}
$newSiblings = $newParent->children()->getCollection()->withOrdered();
$order = 0;
foreach ($newSiblings as $sibling) {