Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates asset alt text to use getThumbAlt #12724

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- Element index pages now have visually-hidden “Sources” headings for screen readers. ([#12961](https://github.com/craftcms/cms/pull/12961))
- Element metadata fields now have visually-hidden “Metadata” headings for screen readers. ([#12961](https://github.com/craftcms/cms/pull/12961))
- Structure elements within element indexes now convey their levels to screen readers. ([#13020](https://github.com/craftcms/cms/pull/13020))
- Image asset thumbnails in the control panel no longer have `alt` attributes if the asset is missing an Alternative Text value. ([#12724](https://github.com/craftcms/cms/pull/12724))
- Non-image asset thumbnails in the control panel now have `alt` attributes set to the file extension. ([#12724](https://github.com/craftcms/cms/pull/12724))

### Administration

Expand Down
9 changes: 7 additions & 2 deletions src/elements/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ public function getImg(mixed $transform = null, ?array $sizes = null): ?Markup
'width' => $this->getWidth(),
'height' => $this->getHeight(),
'srcset' => $sizes ? $this->getSrcset($sizes) : false,
'alt' => $this->alt ?? false,
'alt' => $this->getThumbAlt(),
]);
} else {
$img = null;
Expand Down Expand Up @@ -1957,6 +1957,11 @@ public function getThumbAlt(): ?string
return null;
}

$extension = $this->getExtension();
if (!Image::canManipulateAsImage($extension)) {
return $extension;
}

return $this->alt;
}

Expand Down Expand Up @@ -1998,7 +2003,7 @@ public function getPreviewThumbImg(int $desiredWidth, int $desiredHeight): strin
return Html::tag('img', '', [
'sizes' => "{$thumbSizes[0][0]}px",
'srcset' => implode(', ', $srcsets),
'alt' => $this->alt ?? $this->title,
'alt' => $this->getThumbAlt(),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/src/js/ElementThumbLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Craft.ElementThumbLoader.Worker = Garnish.Base.extend({
var $img = $('<img/>', {
sizes: $container.attr('data-sizes'),
srcset: $container.attr('data-srcset'),
alt: $container.attr('data-alt') || '',
alt: $container.attr('data-alt') || null,
});
this.addListener($img, 'load,error', 'loadNext');
$img.appendTo($container);
Expand Down