diff --git a/local/config/vufind/HierarchyDefault.ini b/local/config/vufind/HierarchyDefault.ini index 3c0a202431083521cedf451212a3839cfd6027f8..84c8aff32f827331cd7c2e390f5bf2404f2b3625 100644 --- a/local/config/vufind/HierarchyDefault.ini +++ b/local/config/vufind/HierarchyDefault.ini @@ -36,4 +36,14 @@ fullHierarchyRecordView = true ; from the Solr index under all conditions -- usually the case unless you have ; conditional filters), you can turn this off for a slight performance gain. ; (default = true) -checkAvailability = true \ No newline at end of file +checkAvailability = true + +; the finc specific TreeRenderer can be configured to set links from tree nodes to +; the desired RecordTabs. Set the RecordTab name as used in the record route +; linkedTabForParents is for Records having children in the tree +; linkedTabForCollections is for DigitalCollection records (mostly also having children) +; linkedTabDefault is for others, meaning standard records here +[TreeRenderer] +linkedTabForParents = "HierarchyTree" +linkedTabForCollections = "HierarchyTree" +linkedTabDefault = "Description" \ No newline at end of file diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php index ae6c6a7a8c34ac573febe638585ac82014b85c56..21b757fc5c18d35e6ba57da4bad3da5ba8961d3e 100644 --- a/module/finc/config/module.config.php +++ b/module/finc/config/module.config.php @@ -189,6 +189,11 @@ $config = [ 'factories' => [ 'finc\Hierarchy\TreeRenderer\JSTree' => 'VuFind\Hierarchy\TreeRenderer\JSTreeFactory' ], + 'delegators' => [ + 'finc\Hierarchy\TreeRenderer\JSTree' => [ + 'finc\Hierarchy\TreeRenderer\JSTreeDelegatorFactory' + ] + ], 'aliases' => [ 'jstree' => 'finc\Hierarchy\TreeRenderer\JSTree' ], diff --git a/module/finc/src/finc/Hierarchy/TreeRenderer/JSTree.php b/module/finc/src/finc/Hierarchy/TreeRenderer/JSTree.php index 36bd4efcfe6d2516374c3ce00b2dbaecf3dcf0d9..27545e6589dd0f06b9c170fccfc37af3fdeb19cd 100644 --- a/module/finc/src/finc/Hierarchy/TreeRenderer/JSTree.php +++ b/module/finc/src/finc/Hierarchy/TreeRenderer/JSTree.php @@ -27,6 +27,8 @@ */ namespace finc\Hierarchy\TreeRenderer; +use Zend\Config\Config; + /** * Hierarchy Tree Renderer * @@ -40,6 +42,15 @@ namespace finc\Hierarchy\TreeRenderer; */ class JSTree extends \VuFind\Hierarchy\TreeRenderer\JSTree { + /** + * @var Config treeRendererConfig + */ + protected $treeRendererConfig; + + public function setConfig(Config $treeRendererConfig) { + $this->treeRendererConfig = $treeRendererConfig; + } + /** * Use the router to build the appropriate URL based on context * @@ -50,12 +61,16 @@ class JSTree extends \VuFind\Hierarchy\TreeRenderer\JSTree */ protected function getContextualUrl($node, $context) { + //set default node type to record + $type = 'record'; if ($node->type == 'collection') { - return $this->getUrlFromRouteCache('collection', $node->id); - } else { - $url = $this->getUrlFromRouteCache('record', $node->id); - return $url; + $type = 'collection'; + } elseif (!empty($node->children)) { + //this is the finc-specific node type for + //hierarchy parents + $type = 'parent'; } + return $this->getUrlFromRouteCache($type, $node->id); } /** @@ -72,20 +87,43 @@ class JSTree extends \VuFind\Hierarchy\TreeRenderer\JSTree static $cache = []; if (!isset($cache[$route])) { if ($route == 'collection') { + $tab = $this->treeRendererConfig->linkedTabForCollections ?? 'HierarchyTree'; $params = [ 'id' => '__record_id__', - 'tab' => 'HierarchyTree' - ]; - $options = [ - 'query' => [ - 'recordID' => '__record_id__' - ] + 'tab' => $tab ]; + if ($tab === 'HierarchyTree') { + $options = [ + 'query' => [ + 'recordID' => '__record_id__' + ] + ]; + } $cache[$route] = $this->router->fromRoute($route, $params, $options); + } elseif ($route == 'parent') { + // this is nearly the same as for collections + // but links on the record view i.e. record route + $tab = $this->treeRendererConfig->linkedTabForParents; + if (empty($tab)) $tab = 'HierarchyTree'; + $params = [ + 'id' => '__record_id__', + 'tab' => $tab + ]; + if ($tab === 'HierarchyTree') { + $options = [ + 'query' => [ + 'recordID' => '__record_id__' + ] + ]; + } + // use route 'record' here to avoid linking to the + // collection view + $cache[$route] = $this->router->fromRoute('record', $params, $options); } else { + $tab = $this->treeRendererConfig->linkedTabDefault ?? 'Description'; $params = [ 'id' => '__record_id__', - 'tab' => 'Description' + 'tab' => $tab ]; $cache[$route] = $this->router->fromRoute($route, $params); } diff --git a/module/finc/src/finc/Hierarchy/TreeRenderer/JSTreeDelegatorFactory.php b/module/finc/src/finc/Hierarchy/TreeRenderer/JSTreeDelegatorFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..96e506c1540bf6e26dd8fe549c1bdb5fad6cfc85 --- /dev/null +++ b/module/finc/src/finc/Hierarchy/TreeRenderer/JSTreeDelegatorFactory.php @@ -0,0 +1,71 @@ +<?php +/** + * JSTree Delegator Factory + * + * A Delegator Factory that registers several listeners at events triggered by the + * VuFind\Search service. + * + * PHP version 7 + * + * Copyright (C) Leipzig University Library 2019. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Finc/Hierarchy + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Page + */ +namespace finc\Hierarchy\TreeRenderer; + +use Interop\Container\ContainerInterface; +use Zend\ServiceManager\Factory\DelegatorFactoryInterface; + +/** + * JSTree Delegator Factory + * + * + * @category VuFind + * @package Finc/Hierarchy + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Page + */ +class JSTreeDelegatorFactory implements DelegatorFactoryInterface +{ + /** + * Creates a delegator of JSTree to add configuration + * + * @param ContainerInterface $container + * @param string $name + * @param callable $callback + * @param array|null $options + * + * @return mixed + */ + public function __invoke( + ContainerInterface $container, + $name, + callable $callback, + array $options = null + ) + { + $instance = call_user_func($callback); + $instance->setConfig( + $container->get('VuFind\Config')->get('HierarchyDefault')->TreeRenderer + ); + return $instance; + } +} \ No newline at end of file