Skip to content
Snippets Groups Projects
Commit a2b8a67d authored by Ere Maijala's avatar Ere Maijala Committed by Demian Katz
Browse files

Allow more services to function in Console mode (#1130)

- Make "Page not found", theme init and cookie manager with limit_by_path setting work.
parent bc427a45
No related merge requests found
...@@ -179,17 +179,20 @@ class Bootstrapper ...@@ -179,17 +179,20 @@ class Bootstrapper
{ {
$callback = function ($event) { $callback = function ($event) {
$serviceManager = $event->getApplication()->getServiceManager(); $serviceManager = $event->getApplication()->getServiceManager();
$viewModel = $serviceManager->get('ViewManager')->getViewModel(); if (!Console::isConsole()) {
$viewModel = $serviceManager->get('ViewManager')->getViewModel();
// Grab the template name from the first child -- we can use this to
// figure out the current template context. // Grab the template name from the first child -- we can use this to
$children = $viewModel->getChildren(); // figure out the current template context.
if (!empty($children)) { $children = $viewModel->getChildren();
$parts = explode('/', $children[0]->getTemplate()); if (!empty($children)) {
$viewModel->setVariable('templateDir', $parts[0]); $parts = explode('/', $children[0]->getTemplate());
$viewModel->setVariable( $viewModel->setVariable('templateDir', $parts[0]);
'templateName', isset($parts[1]) ? $parts[1] : null $viewModel->setVariable(
); 'templateName',
isset($parts[1]) ? $parts[1] : null
);
}
} }
}; };
$this->events->attach('dispatch', $callback); $this->events->attach('dispatch', $callback);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
namespace VuFind\Cookie; namespace VuFind\Cookie;
use Interop\Container\ContainerInterface; use Interop\Container\ContainerInterface;
use Zend\Console\Console;
use Zend\ServiceManager\Factory\FactoryInterface; use Zend\ServiceManager\Factory\FactoryInterface;
/** /**
...@@ -66,7 +67,8 @@ class CookieManagerFactory implements FactoryInterface ...@@ -66,7 +67,8 @@ class CookieManagerFactory implements FactoryInterface
if (isset($config->Cookies->limit_by_path) if (isset($config->Cookies->limit_by_path)
&& $config->Cookies->limit_by_path && $config->Cookies->limit_by_path
) { ) {
$path = $container->get('Request')->getBasePath(); $path = Console::isConsole()
? '' : $container->get('Request')->getBasePath();
if (empty($path)) { if (empty($path)) {
$path = '/'; $path = '/';
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
namespace VuFindTheme; namespace VuFindTheme;
use Zend\Config\Config; use Zend\Config\Config;
use Zend\Console\Console;
use Zend\Mvc\MvcEvent; use Zend\Mvc\MvcEvent;
use Zend\Mvc\View\Http\InjectTemplateListener as BaseInjectTemplateListener; use Zend\Mvc\View\Http\InjectTemplateListener as BaseInjectTemplateListener;
use Zend\Stdlib\RequestInterface as Request; use Zend\Stdlib\RequestInterface as Request;
...@@ -269,10 +270,12 @@ class Initializer ...@@ -269,10 +270,12 @@ class Initializer
protected function sendThemeOptionsToView() protected function sendThemeOptionsToView()
{ {
// Get access to the view model: // Get access to the view model:
$viewModel = $this->serviceManager->get('ViewManager')->getViewModel(); if (!Console::isConsole()) {
$viewModel = $this->serviceManager->get('ViewManager')->getViewModel();
// Send down the view options: // Send down the view options:
$viewModel->setVariable('themeOptions', $this->getThemeOptions()); $viewModel->setVariable('themeOptions', $this->getThemeOptions());
}
} }
/** /**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment