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

Use collection URLs only if collections are enabled in configuration. (#1111)

parent 48659bcb
No related merge requests found
...@@ -79,6 +79,12 @@ class CollectionController extends AbstractRecord ...@@ -79,6 +79,12 @@ class CollectionController extends AbstractRecord
*/ */
protected function showTab($tab, $ajax = false) 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); $result = parent::showTab($tab, $ajax);
if (!$ajax && $result instanceof \Zend\View\Model\ViewModel) { if (!$ajax && $result instanceof \Zend\View\Model\ViewModel) {
$result->setTemplate('collection/view'); $result->setTemplate('collection/view');
......
...@@ -50,14 +50,26 @@ class JSTree extends AbstractBase ...@@ -50,14 +50,26 @@ class JSTree extends AbstractBase
*/ */
protected $router = null; protected $router = null;
/**
* Whether the collections functionality is enabled
*
* @var bool
*/
protected $collectionsEnabled;
/** /**
* Constructor * 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->router = $router;
$this->collectionsEnabled = $collectionsEnabled;
} }
/** /**
...@@ -205,8 +217,12 @@ class JSTree extends AbstractBase ...@@ -205,8 +217,12 @@ class JSTree extends AbstractBase
return $this->getUrlFromRouteCache('collection', $node->id) return $this->getUrlFromRouteCache('collection', $node->id)
. '#tabnav'; . '#tabnav';
} else { } else {
$url = $this->getUrlFromRouteCache($node->type, $node->id); $type = $node->type;
return $node->type == 'collection' if ('collection' === $type && !$this->collectionsEnabled) {
$type = 'record';
}
$url = $this->getUrlFromRouteCache($type, $node->id);
return $type === 'collection'
? $url . '#tabnav' ? $url . '#tabnav'
: $url . '#tree-' . preg_replace('/\W/', '-', $node->id); : $url . '#tree-' . preg_replace('/\W/', '-', $node->id);
} }
......
...@@ -60,8 +60,10 @@ class JSTreeFactory implements \Zend\ServiceManager\Factory\FactoryInterface ...@@ -60,8 +60,10 @@ class JSTreeFactory implements \Zend\ServiceManager\Factory\FactoryInterface
if ($options !== null) { if ($options !== null) {
throw new \Exception('Unexpected options sent to factory!'); throw new \Exception('Unexpected options sent to factory!');
} }
$config = $container->get('VuFind\Config\PluginManager')->get('config');
return new $requestedName( return new $requestedName(
$container->get('ControllerPluginManager')->get('Url') $container->get('ControllerPluginManager')->get('Url'),
!empty($config->Collections->collections)
); );
} }
} }
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