From 00110f2cd323cccd3fb2f6b41d03de2ed355b4a0 Mon Sep 17 00:00:00 2001 From: Ere Maijala <ere.maijala@helsinki.fi> Date: Fri, 23 Feb 2018 19:53:11 +0200 Subject: [PATCH] Use collection URLs only if collections are enabled in configuration. (#1111) --- .../Controller/CollectionController.php | 6 +++++ .../VuFind/Hierarchy/TreeRenderer/JSTree.php | 26 +++++++++++++++---- .../Hierarchy/TreeRenderer/JSTreeFactory.php | 4 ++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/module/VuFind/src/VuFind/Controller/CollectionController.php b/module/VuFind/src/VuFind/Controller/CollectionController.php index f8303f0a94c..b50e1e24f57 100644 --- a/module/VuFind/src/VuFind/Controller/CollectionController.php +++ b/module/VuFind/src/VuFind/Controller/CollectionController.php @@ -79,6 +79,12 @@ class CollectionController extends AbstractRecord */ protected function showTab($tab, $ajax = false) { + // Check that collections are enabled and redirect if necessary + $config = $this->getConfig(); + if (empty($config->Collections->collections)) { + return $this->redirectToRecord(); + } + $result = parent::showTab($tab, $ajax); if (!$ajax && $result instanceof \Zend\View\Model\ViewModel) { $result->setTemplate('collection/view'); diff --git a/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTree.php b/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTree.php index 07ddc43a75f..a5422165804 100644 --- a/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTree.php +++ b/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTree.php @@ -50,14 +50,26 @@ class JSTree extends AbstractBase */ protected $router = null; + /** + * Whether the collections functionality is enabled + * + * @var bool + */ + protected $collectionsEnabled; + /** * Constructor * - * @param \Zend\Mvc\Controller\Plugin\Url $router Router plugin for urls + * @param \Zend\Mvc\Controller\Plugin\Url $router Router plugin for + * urls + * @param bool $collectionsEnabled Whether the + * collections functionality is enabled */ - public function __construct(\Zend\Mvc\Controller\Plugin\Url $router) - { + public function __construct(\Zend\Mvc\Controller\Plugin\Url $router, + $collectionsEnabled + ) { $this->router = $router; + $this->collectionsEnabled = $collectionsEnabled; } /** @@ -205,8 +217,12 @@ class JSTree extends AbstractBase return $this->getUrlFromRouteCache('collection', $node->id) . '#tabnav'; } else { - $url = $this->getUrlFromRouteCache($node->type, $node->id); - return $node->type == 'collection' + $type = $node->type; + if ('collection' === $type && !$this->collectionsEnabled) { + $type = 'record'; + } + $url = $this->getUrlFromRouteCache($type, $node->id); + return $type === 'collection' ? $url . '#tabnav' : $url . '#tree-' . preg_replace('/\W/', '-', $node->id); } diff --git a/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTreeFactory.php b/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTreeFactory.php index 053734c059a..aee81eba699 100644 --- a/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTreeFactory.php +++ b/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTreeFactory.php @@ -60,8 +60,10 @@ class JSTreeFactory implements \Zend\ServiceManager\Factory\FactoryInterface if ($options !== null) { throw new \Exception('Unexpected options sent to factory!'); } + $config = $container->get('VuFind\Config\PluginManager')->get('config'); return new $requestedName( - $container->get('ControllerPluginManager')->get('Url') + $container->get('ControllerPluginManager')->get('Url'), + !empty($config->Collections->collections) ); } } -- GitLab