From d5dea81d948f4c861d18d76b806dc4956f981cb4 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sat, 16 Jan 2016 17:22:08 +0100 Subject: [PATCH] Fix issue when adding folders to subfolders. Also fix when ordering is < 10, and fix when there's no other folder --- classes/controller.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/classes/controller.php b/classes/controller.php index 918c6855..d5761740 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -1066,8 +1066,14 @@ class AdminController } $data = $this->post; - $pages_dir = $this->grav['locator']->findResource('page://'); - $files = Folder::all($pages_dir . $data['route'], ['recursive' => false]); + + if ($data['route'] == '/') { + $path = $this->grav['locator']->findResource('page://'); + } else { + $path = $page = $this->grav['page']->find($data['route'])->path(); + } + + $files = Folder::all($path, ['recursive' => false]); $highestOrder = 0; foreach ($files as $file) { @@ -1075,6 +1081,8 @@ class AdminController if (isset($order[0])) { $theOrder = intval(trim($order[0], '.')); + } else { + $theOrder = 0; } if ($theOrder >= $highestOrder) { @@ -1084,7 +1092,11 @@ class AdminController $orderOfNewFolder = $highestOrder + 1; - Folder::mkdir($pages_dir . $data['route'] . '/' . $orderOfNewFolder . '.' . $data['folder']); + if ($orderOfNewFolder < 10) { + $orderOfNewFolder = '0' . $orderOfNewFolder; + } + + Folder::mkdir($path . '/' . $orderOfNewFolder . '.' . $data['folder']); $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_SAVED'), 'info');