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(); +});