diff --git a/module/VuFind/src/VuFind/Bootstrap.php b/module/VuFind/src/VuFind/Bootstrap.php index 554f2316f94f3ae4dcdb10aa5d97063ddd7b51e4..656401b32d0178021e1eb8b023faee61bb4ec191 100644 --- a/module/VuFind/src/VuFind/Bootstrap.php +++ b/module/VuFind/src/VuFind/Bootstrap.php @@ -139,26 +139,6 @@ class Bootstrap $this->events->attach('dispatch', $callback); } - /** - * Set up flash messenger. - * - * @return void - */ - protected function initFlashMessenger() - { - // Register in view: - $callback = function($event) { - $viewModel = $event->getResult(); - $controller = $event->getTarget(); - if (is_a($viewModel, 'Zend\View\Model\ViewModel') - && is_a($controller, 'Zend\Mvc\Controller\AbstractActionController') - ) { - $viewModel->setVariable('flashMessenger', $controller->flashMessenger()); - } - }; - $this->events->attach('dispatch', $callback); - } - /** * Set view variables representing the current context. * diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php index d461b5fba32dfb45be0c4e71d8f02550c9d67dca..37287aa0076367d371252e661e1a28ed08ebe9e7 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractBase.php +++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php @@ -28,7 +28,7 @@ */ namespace VuFind\Controller; use Zend\Mvc\Controller\AbstractActionController, Zend\ServiceManager\ServiceLocatorInterface, - Zend\ServiceManager\ServiceLocatorAwareInterface; + Zend\ServiceManager\ServiceLocatorAwareInterface, Zend\View\Model\ViewModel; /** * VuFind controller base class (defines some methods that can be shared by other @@ -45,6 +45,23 @@ class AbstractBase extends AbstractActionController { protected $serviceLocator; + /** + * Create a new ViewModel. + * + * @param array $params Parameters to pass to ViewModel constructor. + * + * @return ViewModel + */ + public function createViewModel($params = null) + { + $view = new ViewModel($params); + + // Always make flash messenger available to view: + $view->flashMessenger = $this->flashMessenger(); + + return $view; + } + /** * Get the service locator object. * diff --git a/module/VuFind/src/VuFind/Controller/AbstractSearch.php b/module/VuFind/src/VuFind/Controller/AbstractSearch.php index 583a872d9bf84fb8354711ee1bb2aa5fef8a49bc..3eddbd8855084852d0a5a5e023ec32a60e56b04b 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractSearch.php +++ b/module/VuFind/src/VuFind/Controller/AbstractSearch.php @@ -27,8 +27,8 @@ */ namespace VuFind\Controller; use VuFind\Search\Memory, - VuFind\Search\Options as SearchOptions, VuFind\Search\ResultScroller, - Zend\View\Model\ViewModel; + VuFind\Search\Options as SearchOptions, VuFind\Search\ResultScroller; + /** * VuFind Search Controller * @@ -67,7 +67,7 @@ class AbstractSearch extends AbstractBase */ public function advancedAction() { - $view = new ViewModel(); + $view = $this->createViewModel(); $view->options = SearchOptions::getInstance($this->searchClassId); if ($view->options->getAdvancedSearchAction() === false) { throw new \Exception('Advanced search not supported.'); @@ -90,7 +90,7 @@ class AbstractSearch extends AbstractBase */ public function resultsAction() { - $view = new ViewModel(); + $view = $this->createViewModel(); // Handle saved search requests: $savedId = $this->params()->fromQuery('saved', false); diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index f28928e6966047ecb054fe4eee2768adb7016f1a..f897d64c2ce2194059210a225ec513f0b2c073ab 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -28,8 +28,7 @@ namespace VuFind\Controller; use VuFind\Config\Reader as ConfigReader, VuFind\Exception\Auth as AuthException, - VuFind\Exception\ListPermission as ListPermissionException, - Zend\View\Model\ViewModel; + VuFind\Exception\ListPermission as ListPermissionException; /** * Controller for the user account area. @@ -131,7 +130,7 @@ class MyResearchController extends AbstractBase } // Pass request to view so we can repopulate user parameters in form: - $view = new ViewModel(); + $view = $this->createViewModel(); $view->request = $this->getRequest()->getPost(); return $view; } @@ -169,7 +168,7 @@ class MyResearchController extends AbstractBase } // Make request available to view for form updating: - $view = new ViewModel(); + $view = $this->createViewModel(); $view->request = $this->getRequest()->getPost(); return $view; } @@ -510,7 +509,7 @@ class MyResearchController extends AbstractBase $params->initFromRequest($this->getRequest()->getQuery()); $results = new \VuFind\Search\Favorites\Results($params); $results->performAndProcessSearch(); - return new ViewModel(array('results' => $results)); + return $this->createViewModel(array('results' => $results)); } catch (ListPermissionException $e) { if (!$this->getUser()) { return $this->forceLogin(); diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php index 90ea464118a2cdd4010ee7b7be63a545a5632d8d..21f801f70bd957d3269bf124b25594e09f389127 100644 --- a/module/VuFind/src/VuFind/Controller/SearchController.php +++ b/module/VuFind/src/VuFind/Controller/SearchController.php @@ -48,7 +48,9 @@ class SearchController extends AbstractSearch */ public function homeAction() { - return array('results' => $this->getAdvancedFacets()); + return $this->createViewModel( + array('results' => $this->getAdvancedFacets()) + ); } /**