diff --git a/module/VuFind/src/VuFind/Controller/CollectionController.php b/module/VuFind/src/VuFind/Controller/CollectionController.php index f8303f0a94c15c64067a3bfa20bd319ee655291e..b50e1e24f5791f0e50d8d94792ba45825d603bb2 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 07ddc43a75ff590207f3d579cebec625275c1965..a5422165804a2513017bc9218d3f77145813de32 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 053734c059a7759ad4fdc3d44b132ad847746dbb..aee81eba699d95d0498661ee3d83c2a6a3f2248a 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) ); } }