From c1af35e9aca54d28e152318f215158deb4c96633 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Tue, 29 Dec 2015 19:08:48 +0100 Subject: [PATCH 1/2] Fix for change in https://github.com/getgrav/grav/commit/3eb2a5664aa20ceebf4106156b5b510890a8dee0 Handle in Admin the logic to strip home from Page routes and urls (optional) --- classes/controller.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/classes/controller.php b/classes/controller.php index 37628332..b1348fa8 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -1074,10 +1074,27 @@ class AdminController // Find new parent page in order to build the path. $route = !isset($data['route']) ? dirname($this->admin->route) : $data['route']; - $parent = $route && $route != '/' ? $pages->dispatch($route, true) : $pages->root(); - $obj = $this->admin->page(true); + $config = $this->grav['config']; + $hide_home_route = $config->get('system.home.hide_in_urls', false); + if ($hide_home_route) { + $home_route = $config->get('system.home.alias'); + $topParent = $obj->topParent(); + if (isset($topParent)) { + if ($topParent->route() == $home_route) { + $baseRoute = (string) $topParent->route(); + if ($obj->parent() != $topParent) { + $baseRoute .= $obj->parent()->route(); + } + } + } + + $route = isset($baseRoute) ? $baseRoute : null; + } + + $parent = $route && $route != '/' ? $pages->dispatch($route, true) : $pages->root(); + $original_slug = $obj->slug(); $original_order = intval(trim($obj->order(), '.')); From 52ae7bcf8022962f2f26fd534a537c3da8aaf250 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Tue, 29 Dec 2015 19:31:02 +0100 Subject: [PATCH 2/2] Fix redirect after saving page --- classes/controller.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/classes/controller.php b/classes/controller.php index b1348fa8..9b0db99a 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -1071,12 +1071,13 @@ class AdminController if ($this->view == 'pages') { /** @var Page\Pages $pages */ $pages = $this->grav['pages']; + $config = $this->grav['config']; // Find new parent page in order to build the path. $route = !isset($data['route']) ? dirname($this->admin->route) : $data['route']; $obj = $this->admin->page(true); - $config = $this->grav['config']; + //Handle system.home.hide_in_urls $hide_home_route = $config->get('system.home.hide_in_urls', false); if ($hide_home_route) { $home_route = $config->get('system.home.alias'); @@ -1089,7 +1090,6 @@ class AdminController } } } - $route = isset($baseRoute) ? $baseRoute : null; } @@ -1162,7 +1162,21 @@ class AdminController } } $admin_route = $this->grav['config']->get('plugins.admin.route'); - $redirect_url = '/' . ($multilang ? ($obj->language()) : '') . $admin_route . '/' . $this->view . $obj->route(); + + //Handle system.home.hide_in_urls + $route = $obj->route(); + $hide_home_route = $config->get('system.home.hide_in_urls', false); + if ($hide_home_route) { + $home_route = $config->get('system.home.alias'); + $topParent = $obj->topParent(); + if (isset($topParent)) { + if ($topParent->route() == $home_route) { + $route = (string) $topParent->route() . $route; + } + } + } + + $redirect_url = '/' . ($multilang ? ($obj->language()) : '') . $admin_route . '/' . $this->view . $route; $this->setRedirect($redirect_url); }