Skip to content

Commit

Permalink
Fixed ordering when changing parent of new page
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Jan 14, 2021
1 parent 18b0e01 commit 515eab7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
* Fixed fatal error in PHP 8 when trying to access root page
* Fixed Array->String conversion error when `languages:translations: false` [admin#1896](https://github.com/getgrav/grav-plugin-admin/issues/1896)
* Fixed `Inflector` methods when translation is missing `GRAV.INFLECTOR_*` translations
* Fixed `PageObject::getRoute()` with pages which have no route
* Fixed exception when changing parent of new page [grav-plugin-admin#2018](https://github.com/getgrav/grav-plugin-admin/issues/2018)
* Fixed ordering when changing parent of new page [grav-plugin-admin#2018](https://github.com/getgrav/grav-plugin-admin/issues/2018)

# v1.7.0-rc.20
## 12/15/2020
Expand Down
16 changes: 8 additions & 8 deletions system/src/Grav/Common/Flex/Types/Pages/PageObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ public function move(PageInterface $parent)
*/
protected function reorderSiblings(array $ordering)
{
$storageKey = $this->getMasterKey();
$filesystem = Filesystem::getInstance(false);
$oldParentKey = ltrim($filesystem->dirname("/{$storageKey}"), '/');
$newParentKey = $this->getProperty('parent_key');
$isMoved = $oldParentKey !== $newParentKey;
$order = !$isMoved ? $this->order() : false;

$parent = $this->parent();
if (!$parent) {
throw new RuntimeException('Cannot reorder a page which has no parent');
Expand All @@ -331,13 +338,6 @@ protected function reorderSiblings(array $ordering)
/** @var PageCollection|null $siblings */
$siblings = $siblings->getCollection()->withOrdered()->orderBy(['order' => 'ASC']);

$storageKey = $this->getMasterKey();
$filesystem = Filesystem::getInstance(false);
$oldParentKey = ltrim($filesystem->dirname("/{$storageKey}"), '/');
$newParentKey = $this->getProperty('parent_key');
$isMoved = $oldParentKey !== $newParentKey;
$order = !$isMoved ? $this->order() : false;

if ($storageKey !== null) {
if ($order !== false) {
// Add current page back to the list if it's ordered.
Expand Down Expand Up @@ -370,7 +370,7 @@ protected function reorderSiblings(array $ordering)
$siblings->removeElement($this);

// If menu item was moved, just make it to be the last in order.
if ($isMoved && $order !== false) {
if ($isMoved && $this->order() !== false) {
$parentKey = $this->getProperty('parent_key');
$newParent = $this->getFlexDirectory()->getObject($parentKey, 'storage_key');
$newSiblings = $newParent->children()->getCollection()->withOrdered();
Expand Down

0 comments on commit 515eab7

Please sign in to comment.