|
41 | 41 | $existing = $svg->getAttribute('style'); |
42 | 42 | $svg->setAttribute('style', $existing ? "{$existing}; {$attrStyle}" : $attrStyle); |
43 | 43 | } |
44 | | - $altText = $alt ?? ($isFile ? $image->alt()->value() : null); |
45 | | - if ($altText) { |
46 | | - $svg->setAttribute('aria-label', $altText); |
| 44 | + if (isset($alt)) { |
| 45 | + $svg->setAttribute('aria-label', $alt); |
47 | 46 | $svg->setAttribute('role', 'img'); |
| 47 | + } elseif ($isFile) { |
| 48 | + $altText = $image->alt()->toAltText(); |
| 49 | + if ($altText->isDecorative()) { |
| 50 | + $svg->setAttribute('role', 'presentation'); |
| 51 | + } elseif ($altText->text() !== '') { |
| 52 | + $svg->setAttribute('aria-label', $altText->text()); |
| 53 | + $svg->setAttribute('role', 'img'); |
| 54 | + } |
48 | 55 | } |
49 | 56 | foreach ($attr as $key => $value) { |
50 | 57 | $svg->setAttribute($key, $value); |
|
88 | 95 | $src = $clientBlur |
89 | 96 | ? 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=' |
90 | 97 | : $image->thUri($ratio); |
91 | | - ?> |
| 98 | + $altAttr = isset($alt) ? ['alt' => $alt] : ($isFile ? $image->alt()->toAltText()->toAttr() : []); ?> |
92 | 99 | <?= Html::img($src, [ |
93 | 100 | 'data-thumbhash' => $clientBlur ? $image->th($ratio) : null, |
94 | 101 | 'data-src' => $medianUrl, |
95 | 102 | 'width' => $image->width(), |
96 | 103 | 'height' => $ratio ? floor($image->width() / $ratio) : $image->height(), |
97 | | - 'alt' => $alt ?? ($isFile ? $image->alt() : null), |
98 | 104 | 'loading' => $lazy ? 'lazy' : null, |
99 | 105 | 'draggable' => false, |
100 | 106 | ($lazy ? 'data-srcset' : 'srcset') => $srcsetString, |
|
106 | 112 | "object-position: " . ($focus ?? "50% 50%"), |
107 | 113 | $attrStyle ?: null, |
108 | 114 | ]), '; '), |
| 115 | + ...$altAttr, |
109 | 116 | ...$attr, |
110 | 117 | ]) ?> |
111 | 118 | <?php endif ?> |
|
0 commit comments