From e041e39cb9864f6c53820491c9dd091d8646aa2f Mon Sep 17 00:00:00 2001 From: Rob Lyons <39706150+aSeriousDeveloper@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:18:52 +0000 Subject: [PATCH] Allow withResponsiveImages to be conditionally set (#3742) * Allow withResponsiveImages to be set to false This is to reset the value if it was previously set true, for instance in an additional media library package. * Update ResponsiveImageTest.php test --- src/Conversions/Conversion.php | 4 ++-- tests/ResponsiveImages/ResponsiveImageTest.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Conversions/Conversion.php b/src/Conversions/Conversion.php index 0d679709d..ede08bc23 100644 --- a/src/Conversions/Conversion.php +++ b/src/Conversions/Conversion.php @@ -186,9 +186,9 @@ public function nonOptimized(): self return $this; } - public function withResponsiveImages(): self + public function withResponsiveImages(bool $withResponsiveImages = true): self { - $this->generateResponsiveImages = true; + $this->generateResponsiveImages = $withResponsiveImages; return $this; } diff --git a/tests/ResponsiveImages/ResponsiveImageTest.php b/tests/ResponsiveImages/ResponsiveImageTest.php index 66cf6e560..e745d2780 100644 --- a/tests/ResponsiveImages/ResponsiveImageTest.php +++ b/tests/ResponsiveImages/ResponsiveImageTest.php @@ -112,3 +112,18 @@ expect($media->getResponsiveImageUrls('non-existing-conversion'))->toBe([]); }); + +test('a media instance can be set to not generate responsive urls', function () { + $this + ->testModelWithResponsiveImages + ->addMedia($this->getTestJpg()) + ->withResponsiveImages() + ->withResponsiveImages(false) + ->toMediaCollection(); + + $media = $this->testModelWithResponsiveImages->getFirstMedia(); + + expect($media->hasResponsiveImages())->toBeFalse(); + + expect($media->hasResponsiveImages('thumb'))->toBeFalse(); +});