From 3dbb6c7e69aded9b6fcb11c80d58ed88115da015 Mon Sep 17 00:00:00 2001 From: Alexander Purr <purr@ub.uni-leipzig.de> Date: Tue, 11 Apr 2023 14:39:18 +0200 Subject: [PATCH] refs #18621 [finc] Remove title attribute from hierarchy tree node * prevent from shipping redundant title information * follow up with PR --- .../finc/Hierarchy/TreeRenderer/JSTree.php | 38 +++++++++++++++++++ themes/finc/js/hierarchyTree.js | 3 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/module/finc/src/finc/Hierarchy/TreeRenderer/JSTree.php b/module/finc/src/finc/Hierarchy/TreeRenderer/JSTree.php index 16364aac71a..66943372c9c 100644 --- a/module/finc/src/finc/Hierarchy/TreeRenderer/JSTree.php +++ b/module/finc/src/finc/Hierarchy/TreeRenderer/JSTree.php @@ -142,4 +142,42 @@ class JSTree extends \VuFind\Hierarchy\TreeRenderer\JSTree $this->dataSource->setRecordDriver($this->recordDriver); return $this->dataSource; } + + /** + * Almost complete copy from vufind's JStree: + * remove just title attribute + * + * @param object $node JSON object of a node/top node + * @param string $context Record or Collection + * @param string $hierarchyID Collection ID + * + * @return array + * + * @inheritdoc + */ + protected function buildNodeArray($node, $context, $hierarchyID) + { + $escaper = new \Laminas\Escaper\Escaper('utf-8'); + $ret = [ + 'id' => preg_replace('/\W/', '-', $node->id), + 'text' => $escaper->escapeHtml($node->title), + 'li_attr' => [ + 'recordid' => $node->id + ], + 'a_attr' => [ + 'href' => $this->getContextualUrl($node, $context), + // Remove redundant title attribute - refs #18621 + //'title' => $node->title + ], + 'type' => $node->type + ]; + if (isset($node->children)) { + $ret['children'] = []; + for ($i = 0;$i < count($node->children);$i++) { + $ret['children'][$i] = $this + ->buildNodeArray($node->children[$i], $context, $hierarchyID); + } + } + return $ret; + } } diff --git a/themes/finc/js/hierarchyTree.js b/themes/finc/js/hierarchyTree.js index 99dcab2b880..262e84c2519 100644 --- a/themes/finc/js/hierarchyTree.js +++ b/themes/finc/js/hierarchyTree.js @@ -132,7 +132,8 @@ function buildJSONNodes(xml) { li_attr: { recordid: id.text() }, a_attr: { href: name.attr('href'), - title: name.text() + // Remove redundant title attribute - refs #18621 + // title: name.text() }, type: name.attr('href').match(/\/Collection\//) ? 'collection' : 'record', children: buildJSONNodes(this) -- GitLab