From a56599314127c7030e33ba9abbb50ec16ca862e2 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Fri, 9 Mar 2018 17:31:11 -0700 Subject: [PATCH] Automatically redirect to new `admin_route` after changing it #1371 --- CHANGELOG.md | 6 ++++++ admin.php | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33966ded..977675ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.7.1 +## mm/dd/2018 + +1. [](#bugfix) + * Automatically redirect to new `admin_route` after changing it [#1371](https://github.com/getgrav/grav-plugin-admin/issues/1371) + # v1.7.0 ## 03/09/2018 diff --git a/admin.php b/admin.php index f6f817cc..8c604f08 100644 --- a/admin.php +++ b/admin.php @@ -606,6 +606,7 @@ class AdminPlugin extends Plugin 'onAssetsInitialized' => ['onAssetsInitialized', 1000], 'onAdminRegisterPermissions' => ['onAdminRegisterPermissions', 0], 'onOutputGenerated' => ['onOutputGenerated', 0], + 'onAdminAfterSave' => ['onAdminAfterSave', 0], ]); // Autoload classes @@ -772,6 +773,16 @@ class AdminPlugin extends Plugin return false; } + public function onAdminAfterSave(Event $event) + { + // Special case to redirect after changing the admin route to avoid 'breaking' + $obj = $event['object']; + if (isset($obj->route) && $this->admin_route !== $obj->route) { + $redirect = str_replace($this->admin_route, $obj->route, $this->uri->path() ); + $this->grav->redirect($redirect); + } + } + /** * Provide the tools for the Tools page, currently only direct install *