Skip to content

Commit

Permalink
Allow withResponsiveImages to be conditionally set (#3742)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aSeriousDeveloper authored Dec 9, 2024
1 parent fcc900a commit e041e39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Conversions/Conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/ResponsiveImages/ResponsiveImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit e041e39

Please # to comment.