From d0582bb516d25ffbd6624a1e787ad6b7da312fde Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Fri, 25 Aug 2023 16:14:11 +0300 Subject: [PATCH] [FINNA-514] Add support for general authority id's in popover. Relaxes the rules and adds configuration to enable authority linking based on plain identifiers. Also adds a check to hide the authority record link if an authority record cannot be found. --- local/config/finna/datasources.ini.sample | 3 ++- module/Finna/src/Finna/AjaxHandler/GetFieldInfo.php | 4 ++-- .../src/Finna/RecordDriver/Feature/FinnaRecordTrait.php | 9 +++++++++ themes/finna2/js/finna-record.js | 6 ++++++ .../DefaultRecord/popover-link-element.phtml | 4 +++- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/local/config/finna/datasources.ini.sample b/local/config/finna/datasources.ini.sample index 26ecd68da51..26c293b6bbe 100644 --- a/local/config/finna/datasources.ini.sample +++ b/local/config/finna/datasources.ini.sample @@ -8,7 +8,8 @@ ; disablePatronFunctions Set true if datasource does not have patron functionality, can be left out ; authority[] Map to authority index sources where is authority record type ; (corporateBody, person) or * for any; -; authority_id_regex[] = Regex for whitelisting allowed authority ids. +; authority_id_regex[] = Regex for allowed authority ids (to be prefixed with the source from authority setting). +; authority_plain_id_regex[] = Regex for allowed authority ids (to be used as is). ; authority_external_link_label_regex = Regex for parsing external link label into title and subtitle, ; parts, for example: /^(Verkkosivut|Kotisivut|Wikipedia),\s*(.*)$/ ; diff --git a/module/Finna/src/Finna/AjaxHandler/GetFieldInfo.php b/module/Finna/src/Finna/AjaxHandler/GetFieldInfo.php index 3752ce24d71..8e712ed3bf7 100644 --- a/module/Finna/src/Finna/AjaxHandler/GetFieldInfo.php +++ b/module/Finna/src/Finna/AjaxHandler/GetFieldInfo.php @@ -150,7 +150,6 @@ public function handleRequest(Params $params) $authIds && $authorityFields && ($authIds[0] ?? false) - && preg_match('/^[\w_-]+\./', $authIds[0]) ) { try { $authority = $this->loader->load( @@ -185,7 +184,8 @@ public function handleRequest(Params $params) ) ); - return $this->formatResponse(compact('html')); + $isAuthority = $authority ? true : false; + return $this->formatResponse(compact('html', 'isAuthority')); } /** diff --git a/module/Finna/src/Finna/RecordDriver/Feature/FinnaRecordTrait.php b/module/Finna/src/Finna/RecordDriver/Feature/FinnaRecordTrait.php index aa74d6dd28a..43296d7e065 100644 --- a/module/Finna/src/Finna/RecordDriver/Feature/FinnaRecordTrait.php +++ b/module/Finna/src/Finna/RecordDriver/Feature/FinnaRecordTrait.php @@ -372,6 +372,15 @@ public function getAuthorityId($id, $type = '*') if ($idRegex && !preg_match($idRegex, $id)) { return null; } + + $plainIdRegex + = $this->datasourceSettings[$recordSource]['authority_plain_id_regex'][$type] + ?? $this->datasourceSettings[$recordSource]['authority_plain_id_regex']['*'] + ?? null; + if ($plainIdRegex && preg_match($plainIdRegex, $id)) { + return $id; + } + return "$authSrc.$id"; } diff --git a/themes/finna2/js/finna-record.js b/themes/finna2/js/finna-record.js index 5ab50f826b5..e0169816aac 100644 --- a/themes/finna2/js/finna-record.js +++ b/themes/finna2/js/finna-record.js @@ -513,6 +513,12 @@ finna.record = (function finnaRecord() { finna.layout.initTruncate(fieldInfo); } fixPosition(field.querySelector('.field-info')); + if (typeof response.data.isAuthority !== 'undefined' && !response.data.isAuthority) { + // No authority record; hide any links that require it: + field.querySelectorAll('.authority-page').forEach(el => { + el.remove(); + }); + } }).catch(function handleError() { fieldInfo.textContent = VuFind.translate('error_occurred'); }); diff --git a/themes/finna2/templates/RecordDriver/DefaultRecord/popover-link-element.phtml b/themes/finna2/templates/RecordDriver/DefaultRecord/popover-link-element.phtml index 241d16b702d..eab8e02dd6f 100644 --- a/themes/finna2/templates/RecordDriver/DefaultRecord/popover-link-element.phtml +++ b/themes/finna2/templates/RecordDriver/DefaultRecord/popover-link-element.phtml @@ -23,7 +23,9 @@ $additionalDataElem = !empty($this->additionalDataHtml) ? "

escapeHtml($this->label)?>

fieldLinks as $link): ?> - transEsc($link['linkText'])?>
+ + transEsc($link['linkText'])?>
+
ids): ?>