From 346d1941253e17ab2046095f4de2ddb26e225624 Mon Sep 17 00:00:00 2001 From: "pmoreno.rodriguez" Date: Fri, 25 Oct 2024 11:42:20 +0200 Subject: [PATCH] New Trait for fetchPriority attribute in images (#3850) --- system/blueprints/config/system.yaml | 11 +++++ system/config/system.yaml | 1 + .../Media/Traits/ImageFetchPriorityTrait.php | 40 +++++++++++++++++++ .../Grav/Common/Page/Medium/ImageMedium.php | 2 + 4 files changed, 54 insertions(+) create mode 100644 system/src/Grav/Common/Media/Traits/ImageFetchPriorityTrait.php diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index b0ad371d0..352d4193f 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -1311,6 +1311,17 @@ form: auto: Auto sync: Sync async: Async + + images.defaults.fetchpriority: + type: select + size: small + label: PLUGIN_ADMIN.IMAGES_FETCHPRIORITY + help: PLUGIN_ADMIN.IMAGES_FETCHPRIORITY_HELP + highlight: auto + options: + auto: Auto + high: High + low: Low images.seofriendly: type: toggle diff --git a/system/config/system.yaml b/system/config/system.yaml index 3495c448b..1280f7d13 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -169,6 +169,7 @@ images: defaults: loading: auto # Let browser pick [auto|lazy|eager] decoding: auto # Let browser pick [auto|sync|async] + fetchpriority: auto # Let browser pick [auto|high|low] watermark: image: 'system://images/watermark.png' # Path to a watermark image position_y: 'center' # top|center|bottom diff --git a/system/src/Grav/Common/Media/Traits/ImageFetchPriorityTrait.php b/system/src/Grav/Common/Media/Traits/ImageFetchPriorityTrait.php new file mode 100644 index 000000000..af20a975a --- /dev/null +++ b/system/src/Grav/Common/Media/Traits/ImageFetchPriorityTrait.php @@ -0,0 +1,40 @@ +get('system.images.defaults.fetchpriority', 'auto'); + } + + // Validate the provided value (similar to loading and decoding attributes) + if ($value !== null && $value !== 'auto') { + $this->attributes['fetchpriority'] = $value; + } + + return $this; + } + +} \ No newline at end of file diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 4de211bee..580e9f586 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -16,6 +16,7 @@ use Grav\Common\Media\Interfaces\MediaLinkInterface; use Grav\Common\Media\Traits\ImageLoadingTrait; use Grav\Common\Media\Traits\ImageDecodingTrait; +use Grav\Common\Media\Traits\ImageFetchPriorityTrait; use Grav\Common\Media\Traits\ImageMediaTrait; use Grav\Common\Utils; use Gregwar\Image\Image; @@ -32,6 +33,7 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate use ImageMediaTrait; use ImageLoadingTrait; use ImageDecodingTrait; + use ImageFetchPriorityTrait; /** * @var mixed|string