Skip to content

Commit e693b39

Browse files
authored
fix: add fetchpriority attribute to img_attrs handling (#227)
1 parent 3d8d21b commit e693b39

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

phpstan.baseline.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,12 @@ parameters:
372372
count: 1
373373
path: src/Bridge/Twig/Extension/ImageExtension.php
374374

375+
-
376+
message: '#^Cannot access offset ''fetchpriority'' on mixed\.$#'
377+
identifier: offsetAccess.nonOffsetAccessible
378+
count: 2
379+
path: src/Bridge/Twig/Extension/ImageExtension.php
380+
375381
-
376382
message: '#^Cannot access offset ''loading'' on mixed\.$#'
377383
identifier: offsetAccess.nonOffsetAccessible

src/Bridge/Twig/Extension/ImageExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ function (array $context, string $path, array $options = []): string {
9696
'class' => $options['img_attrs']['class'] ?? null,
9797
'style' => $options['img_attrs']['style'] ?? null,
9898
'alt' => $options['img_attrs']['alt'] ?? $options['attrs']['alt'] ?? null,
99+
'fetchpriority' => $options['img_attrs']['fetchpriority'] ?? $options['attrs']['fetchpriority'] ?? null,
99100
'loading' => $options['img_attrs']['loading'] ?? $options['attrs']['loading'] ?? 'lazy',
100101
'decoding' => $options['img_attrs']['loading'] ?? $options['attrs']['decoding'] ?? 'async',
101102
]);

tests/functional/site/content/articles/images/images.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ This is an asset lookup: {{ yassg_thumbnail(item.image) }}
1919

2020
![Logo]({{ yassg_thumbnail(item.image, {width: 400, height: 200, gravity: "no"}) }})
2121

22-
{{ yassg_picture(item.image, {width: 400, height: 200, gravity: "no", attrs: {alt: "Hello", class: "prose", style: "border: 1px solid red"}, img_attrs: {class: "mb-rounded"}}) }}
22+
{{ yassg_picture(item.image, {width: 400, height: 200, gravity: "no", attrs: {alt: "Hello", class: "prose", style: "border: 1px solid red"}, img_attrs: {class: "mb-rounded", fetchpriority: "high"}}) }}

tests/functional/site/fixtures/en/article/images/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ <h1>Images!</h1>
4646
<p>This is an asset lookup: /sub/dir/another/content/articles/images/image.6ec7e8a4.webp</p>
4747
<p><img src="/sub/dir/another/content/articles/images/image.4de2c22b.webp" alt="Logo" /></p>
4848
<p><img src="/sub/dir/another/content/articles/images/image.5c87cfff.webp" alt="Logo" /></p>
49-
<p><picture class="prose" style="border: 1px solid red"><source type="image/avif" srcset="/sub/dir/another/content/articles/images/image.f72ab4b6.avif 1x, /sub/dir/another/content/articles/images/image.db2a185c.avif 2x"/><source type="image/webp" srcset="/sub/dir/another/content/articles/images/image.5c87cfff.webp 1x, /sub/dir/another/content/articles/images/image.3fc9b4bd.webp 2x"/><source type="image/png" srcset="/sub/dir/another/content/articles/images/image.86315aa7.png 1x, /sub/dir/another/content/articles/images/image.6d24603a.png 2x"/><img src="/sub/dir/another/content/articles/images/image.86315aa7.png" srcset="/sub/dir/another/content/articles/images/image.86315aa7.png 1x, /sub/dir/another/content/articles/images/image.6d24603a.png 2x" width="400" height="200" class="mb-rounded" alt="Hello" loading="lazy" decoding="async" /></picture></p>
49+
<p><picture class="prose" style="border: 1px solid red"><source type="image/avif" srcset="/sub/dir/another/content/articles/images/image.f72ab4b6.avif 1x, /sub/dir/another/content/articles/images/image.db2a185c.avif 2x"/><source type="image/webp" srcset="/sub/dir/another/content/articles/images/image.5c87cfff.webp 1x, /sub/dir/another/content/articles/images/image.3fc9b4bd.webp 2x"/><source type="image/png" srcset="/sub/dir/another/content/articles/images/image.86315aa7.png 1x, /sub/dir/another/content/articles/images/image.6d24603a.png 2x"/><img src="/sub/dir/another/content/articles/images/image.86315aa7.png" srcset="/sub/dir/another/content/articles/images/image.86315aa7.png 1x, /sub/dir/another/content/articles/images/image.6d24603a.png 2x" width="400" height="200" class="mb-rounded" alt="Hello" fetchpriority="high" loading="lazy" decoding="async" /></picture></p>
5050

5151
</div>
5252
</div>

0 commit comments

Comments
 (0)