diff --git a/classes/admin.php b/classes/admin.php index 4af257e1..212aafe9 100644 --- a/classes/admin.php +++ b/classes/admin.php @@ -684,6 +684,26 @@ class Admin return $parent_route; } + /** + * Static helper method to return the last used page name + * + * @return string + */ + public static function getLastPageName() + { + return Grav::instance()['session']->lastPageName ?: 'default'; + } + + /** + * Static helper method to return the last used page route + * + * @return string + */ + public static function getLastPageRoute() + { + return Grav::instance()['session']->lastPageRoute ?: self::route(); + } + /** * Determine if the plugin or theme info passed is from Team Grav * diff --git a/classes/controller.php b/classes/controller.php index 7d9625fa..89529e6d 100644 --- a/classes/controller.php +++ b/classes/controller.php @@ -1030,6 +1030,11 @@ class AdminController $path = $route . '/' . $folder; $this->admin->session()->{$path} = $data; + + // Store the name and route of a page, to be used prefilled defaults of the form in the future + $this->admin->session()->lastPageName = $data['name']; + $this->admin->session()->lastPageRoute = $data['route']; + $this->setRedirect("{$this->view}/". ltrim($path, '/')); return true;