Automatically redirect to new admin_route after changing it #1371

This commit is contained in:
Andy Miller
2018-03-09 17:31:11 -07:00
parent dd5c96495c
commit a565993141
2 changed files with 17 additions and 0 deletions

View File

@@ -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

View File

@@ -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
*