From 906e6e14730356ec6888e058ef9b5200274773a3 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Mon, 22 Jan 2018 09:31:08 -0500 Subject: [PATCH] Add ability to configure default actions (not just controllers). --- config/vufind/config.ini | 10 +++++---- .../src/VuFind/Controller/IndexController.php | 22 +++++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/config/vufind/config.ini b/config/vufind/config.ini index e590deb7a10..81dc55cc7f5 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -86,12 +86,14 @@ displayDateFormat = "m-d-Y" ; A string used to format user interface time strings using the PHP date() function ; default is H:i (HH:MM 23:01) displayTimeFormat = "H:i" -; The base VuFind URL will load the "Home" action of this module unless the user -; is logged in: +; The base VuFind URL will load this controller unless the user is logged in: defaultModule = Search -; The base VuFind URL will load the "Home" action of this module when the user -; is logged in: +; When defaultModule is used, this action will be triggered (default = Home) +;defaultAction = Home +; The base VuFind URL will load this controller when the user is logged in: defaultLoggedInModule = MyResearch +; When defaultLoggedInModule is used, this action will be triggered (default = Home) +;defaultLoggedInAction = Home ; The route VuFind will send users to following a log out operation. Set to false ; or omit to attempt to retain the user's current context after log out. ;logOutRoute = home diff --git a/module/VuFind/src/VuFind/Controller/IndexController.php b/module/VuFind/src/VuFind/Controller/IndexController.php index a88057cde53..d1c4c276962 100644 --- a/module/VuFind/src/VuFind/Controller/IndexController.php +++ b/module/VuFind/src/VuFind/Controller/IndexController.php @@ -75,12 +75,20 @@ class IndexController extends \Zend\Mvc\Controller\AbstractActionController */ public function homeAction() { - $loggedInModule = isset($this->config->Site->defaultLoggedInModule) - ? $this->config->Site->defaultLoggedInModule : 'MyResearch'; - $loggedOutModule = isset($this->config->Site->defaultModule) - ? $this->config->Site->defaultModule : 'Search'; - $module = $this->authManager->isLoggedIn() - ? $loggedInModule : $loggedOutModule; - return $this->forward()->dispatch($module, ['action' => 'Home']); + // Load different configurations depending on whether we're logged in or not: + if ($this->authManager->isLoggedIn()) { + $controller = isset($this->config->Site->defaultLoggedInModule) + ? $this->config->Site->defaultLoggedInModule : 'MyResearch'; + $actionConfig = 'defaultLoggedInAction'; + } else { + $controller = isset($this->config->Site->defaultModule) + ? $this->config->Site->defaultModule : 'Search'; + $actionConfig = 'defaultAction'; + } + $action = isset($this->config->Site->$actionConfig) + ? $this->config->Site->$actionConfig : 'Home'; + + // Forward to the appropriate controller and action: + return $this->forward()->dispatch($controller, compact('action')); } } -- GitLab