diff --git a/local/config/vufind/config.ini b/local/config/vufind/config.ini index ba72c6c8e788d89465b478352c796b6ec12494a8..779730170c56aea51ba963fcbfe91909d7c8dfcd 100644 --- a/local/config/vufind/config.ini +++ b/local/config/vufind/config.ini @@ -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 diff --git a/module/finc/src/finc/View/Helper/Root/Record.php b/module/finc/src/finc/View/Helper/Root/Record.php index c7117e000c20d159e2d93575dfd7706d58610e12..f6e0ea4d28767304774853e80e54191657f0dbd8 100644 --- a/module/finc/src/finc/View/Helper/Root/Record.php +++ b/module/finc/src/finc/View/Helper/Root/Record.php @@ -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