From 1e36dc458dcbe516968b70549e12b6f53114ef0c Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Tue, 1 Oct 2024 07:45:42 +0200 Subject: [PATCH] Improve accessibility of cover images --- .../src/VuFind/View/Helper/Root/Record.php | 27 ++++++++++--------- .../DefaultRecord/collection-info.phtml | 2 +- .../RecordDriver/DefaultRecord/core.phtml | 2 +- .../RecordDriver/DefaultRecord/cover.phtml | 15 ++++++----- .../templates/RecordDriver/EDS/cover.phtml | 16 ++++++----- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Record.php b/module/VuFind/src/VuFind/View/Helper/Root/Record.php index 2c71299b1cc..bb992434447 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Record.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Record.php @@ -538,15 +538,16 @@ public function getCheckbox($idPrefix = '', $formAttr = false, $number = null) /** * Render a cover for the current record. * - * @param string $context Context of code being generated - * @param string $default The default size of the cover - * @param string $link The link for the anchor + * @param string $context Context of code being generated + * @param string $default The default size of the cover + * @param string $link The link for the anchor + * @param bool $linkUnique Is there no other link with the same href? * * @return string */ - public function getCover($context, $default, $link = false) + public function getCover($context, $default, $link = false, $linkUnique = false) { - $details = $this->getCoverDetails($context, $default, $link); + $details = $this->getCoverDetails($context, $default, $link, $linkUnique); return $details['html']; } @@ -575,20 +576,22 @@ protected function getPreviewCoverLinkSetting($context) /** * Get the rendered cover plus some useful parameters. * - * @param string $context Context of code being generated - * @param string $default The default size of the cover - * @param string|array|false $link The href link for the anchor (false - * for no link, or a string to use as an href, or an array of attributes - * to include in the anchor tag) + * @param string $context Context of code being generated + * @param string $default The default size of the cover + * @param string|array|false $link The href link for the anchor + * (false for no link, or a string to use as an href, or an array of + * attributes to include in the anchor tag) + * @param bool $linkUnique Is there no other link with the + * same href? * * @return array */ - public function getCoverDetails($context, $default, $link = false) + public function getCoverDetails($context, $default, $link = false, $linkUnique = false) { $linkAttributes = is_string($link) ? ['href' => $link] : (is_array($link) ? $link : []); - $details = compact('linkAttributes', 'context') + [ + $details = compact('linkAttributes', 'linkUnique', 'context') + [ 'driver' => $this->driver, 'cover' => false, 'size' => false, 'linkPreview' => $this->getPreviewCoverLinkSetting($context), ]; diff --git a/themes/bootstrap3/templates/RecordDriver/DefaultRecord/collection-info.phtml b/themes/bootstrap3/templates/RecordDriver/DefaultRecord/collection-info.phtml index 38e332252eb..d50aebf595d 100644 --- a/themes/bootstrap3/templates/RecordDriver/DefaultRecord/collection-info.phtml +++ b/themes/bootstrap3/templates/RecordDriver/DefaultRecord/collection-info.phtml @@ -2,7 +2,7 @@
record($this->driver)->getQRCode('core'); - $coverDetails = $this->record($this->driver)->getCoverDetails('collection-info', 'medium', $this->record($this->driver)->getThumbnail('large')); + $coverDetails = $this->record($this->driver)->getCoverDetails('collection-info', 'medium', $this->record($this->driver)->getThumbnail('large'), true); $cover = $coverDetails['html']; $preview = $this->record($this->driver)->getPreviews(); ?> diff --git a/themes/bootstrap3/templates/RecordDriver/DefaultRecord/core.phtml b/themes/bootstrap3/templates/RecordDriver/DefaultRecord/core.phtml index d9c5409ee40..b3867e8d1b8 100644 --- a/themes/bootstrap3/templates/RecordDriver/DefaultRecord/core.phtml +++ b/themes/bootstrap3/templates/RecordDriver/DefaultRecord/core.phtml @@ -6,7 +6,7 @@ $QRCode = $this->record($this->driver)->getQRCode('core'); $largeImage = $this->record($this->driver)->getThumbnail('large'); $linkAttributes = $largeImage ? ['href' => $largeImage, 'data-lightbox-image' => 'true'] : []; - $coverDetails = $this->record($this->driver)->getCoverDetails('core', 'medium', $linkAttributes); + $coverDetails = $this->record($this->driver)->getCoverDetails('core', 'medium', $linkAttributes, true); $cover = $coverDetails['html']; $preview = ($this->previewOverride ?? false) ? $this->previewOverride : $this->record($this->driver)->getPreviews(); diff --git a/themes/bootstrap3/templates/RecordDriver/DefaultRecord/cover.phtml b/themes/bootstrap3/templates/RecordDriver/DefaultRecord/cover.phtml index ae92b633150..7df0e07bda2 100644 --- a/themes/bootstrap3/templates/RecordDriver/DefaultRecord/cover.phtml +++ b/themes/bootstrap3/templates/RecordDriver/DefaultRecord/cover.phtml @@ -4,20 +4,23 @@ if ($linkAttributes && !isset($linkAttributes['class'])) { $linkAttributes['class'] = 'record-cover-link'; } - $alt = $linkAttributes ? trim($this->driver->tryMethod('getTitle') ?? '') : ''; ?> -htmlAttributes($linkAttributes)?>> + + linkUnique): ?>tabindex="-1" aria-hidden="true"> + + diff --git a/themes/bootstrap3/templates/RecordDriver/EDS/cover.phtml b/themes/bootstrap3/templates/RecordDriver/EDS/cover.phtml index 237e159e952..b632c8fa33e 100644 --- a/themes/bootstrap3/templates/RecordDriver/EDS/cover.phtml +++ b/themes/bootstrap3/templates/RecordDriver/EDS/cover.phtml @@ -1,11 +1,15 @@ link && $cover !== false ? trim($this->driver->tryMethod('getTitle') ?? '') : ''; + // we don't want to link the icons ($cover === false) (it looks weird) + $includeLinkInMarkup = $this->link && $cover !== false; ?> -link && !empty($alt)): ?> + + linkUnique): ?>tabindex="-1" aria-hidden="true"> + +