From d2daa17352882c56229804207de8f18de24cde2d Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Thu, 1 Oct 2015 15:33:33 +0200 Subject: [PATCH] Add static helper methods to be used by the new page blueprints, and store the information in the session when creating a new page --- classes/admin.php | 20 ++++++++++++++++++++ classes/controller.php | 5 +++++ 2 files changed, 25 insertions(+) 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;