Skip to content
Snippets Groups Projects
Commit b7d02f77 authored by André Lahmann's avatar André Lahmann Committed by Robert Lange
Browse files

refs #21209 [finc] add ability to change link description via link rewrite

* set https as standard protocol if no specific protocol is defined in given url
parent 886621fc
No related merge requests found
......@@ -2027,6 +2027,8 @@ remove[] = "gndmusic"
; identifier[function] calls a function if available with the link as parameter.
; The function performed on the url *before* replacing with the replacement. It is
; intended to perform url-encoding links so they can be used as parameter value.
; identifier[description] will replace the link description with the given value if
; the url was successfully replaced or a method got called upon it.
; Examples:
; url[pattern] = url.pattern.to.resolve.link
; url[method] = resolveLink
......
......@@ -376,6 +376,15 @@ class Record extends \VuFind\View\Helper\Root\Record
protected function rewriteLink(&$link)
{
$rewrite = $this->config->LinksRewrite->toArray();
// helper function to replace the link description with a configured value
$overwriteDescription = function (&$link, $currentRewrite) {
// if another link description is configured use this instead
if (isset($currentRewrite['description'])) {
$link['desc'] = $currentRewrite['description'];
}
};
foreach ($rewrite as $r) {
// is remove pattern than suppress link refs #10834
if (isset($r['remove'])) {
......@@ -411,15 +420,21 @@ class Record extends \VuFind\View\Helper\Root\Record
1,
$count
);
if ($count) {
// overwrite description as we have a successful replace
$overwriteDescription($link, $r);
}
// add http if needed
// @to-do make it https compatible
if (!preg_match('/^(https?:\/\/)/', $link['url'])) {
$link['url'] = 'http://' . $link['url'];
$link['url'] = 'https://' . $link['url'];
}
}
// is method set so call alternatively method proceed link
if (isset($r['method']) && method_exists($this, $r['method'])) {
$link['url'] = $this->$r['method']($link['url']);
// overwrite description as we called the defined method
$overwriteDescription($link, $r);
} // end if isset method
} // end if isset pattern
} // end foreach
......
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