Skip to content

Commit

Permalink
[FINNA-514] Add support for general authority id's in popover.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EreMaijala committed Sep 6, 2023
1 parent 2f6ccf2 commit d0582bb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion local/config/finna/datasources.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
; disablePatronFunctions Set true if datasource does not have patron functionality, can be left out
; authority[<type>] Map to authority index sources where <type> is authority record type
; (corporateBody, person) or * for any;
; authority_id_regex[<type>] = Regex for whitelisting allowed authority ids.
; authority_id_regex[<type>] = Regex for allowed authority ids (to be prefixed with the source from authority setting).
; authority_plain_id_regex[<type>] = 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*(.*)$/
;
Expand Down
4 changes: 2 additions & 2 deletions module/Finna/src/Finna/AjaxHandler/GetFieldInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public function handleRequest(Params $params)
$authIds
&& $authorityFields
&& ($authIds[0] ?? false)
&& preg_match('/^[\w_-]+\./', $authIds[0])
) {
try {
$authority = $this->loader->load(
Expand Down Expand Up @@ -185,7 +184,8 @@ public function handleRequest(Params $params)
)
);

return $this->formatResponse(compact('html'));
$isAuthority = $authority ? true : false;
return $this->formatResponse(compact('html', 'isAuthority'));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
6 changes: 6 additions & 0 deletions themes/finna2/js/finna-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ $additionalDataElem = !empty($this->additionalDataHtml) ? "<span class=\"field-a
<div class="content">
<h2><?=$this->escapeHtml($this->label)?></h2>
<?php foreach ($this->fieldLinks as $link): ?>
<a href="<?=$link['escapedUrl']?>"><?=$this->transEsc($link['linkText'])?></a><br>
<span class="<?=$this->escapeHtmlAttr($link['linkType'])?>">
<a href="<?=$link['escapedUrl']?>"><?=$this->transEsc($link['linkText'])?></a><br>
</span>
<?php endforeach; ?>
<?php if ($this->ids): ?>
<div class="dynamic-content">
Expand Down

0 comments on commit d0582bb

Please sign in to comment.