From 53f1ee99c296f6e7021a6b0367723b78a5b444e3 Mon Sep 17 00:00:00 2001 From: Balsakup Date: Wed, 30 Mar 2022 15:58:28 +0200 Subject: [PATCH 1/3] Fix Htmlable render media --- src/MediaCollections/HtmlableMedia.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/MediaCollections/HtmlableMedia.php b/src/MediaCollections/HtmlableMedia.php index 07d6abcd2..a545ba091 100644 --- a/src/MediaCollections/HtmlableMedia.php +++ b/src/MediaCollections/HtmlableMedia.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Support\Htmlable; use Spatie\MediaLibrary\Conversions\ConversionCollection; use Spatie\MediaLibrary\Conversions\ImageGenerators\Image; +use Spatie\MediaLibrary\Conversions\ImageGenerators\ImageGeneratorFactory; use Spatie\MediaLibrary\MediaCollections\Models\Media; class HtmlableMedia implements Htmlable, \Stringable @@ -43,7 +44,9 @@ public function lazy(): self public function toHtml() { - if (! (new Image())->canHandleMime($this->media->mime_type)) { + $imageGenerator = ImageGeneratorFactory::forMedia($this->media) ?? new Image(); + + if (! $imageGenerator->canHandleMime($this->media->mime_type)) { return ''; } From 2f07c9cdddb25670d0dcd82e6dbc6ff2dbefcf88 Mon Sep 17 00:00:00 2001 From: Balsakup Date: Wed, 30 Mar 2022 18:54:01 +0200 Subject: [PATCH 2/3] Fix test & add test --- tests/Feature/Media/ToHtmlTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/Feature/Media/ToHtmlTest.php b/tests/Feature/Media/ToHtmlTest.php index 177928596..1e964b96a 100644 --- a/tests/Feature/Media/ToHtmlTest.php +++ b/tests/Feature/Media/ToHtmlTest.php @@ -48,12 +48,23 @@ test('converting a non image to an image tag will not blow up', function () { $media = $this->testModelWithConversion - ->addMedia($this->getTestPdf()) + ->addMedia($this->getTestTiff()) ->toMediaCollection(); expect($media->img())->toEqual(''); }); +it('can render pdf thumbnail as an image', function () { + $media = $this->testModelWithConversion + ->addMedia($this->getTestPdf()) + ->toMediaCollection(); + + $this->assertEquals( + "id}/conversions/test-thumb.jpg\" alt=\"test\">", + $media->img('thumb'), + ); +}); + it('can render itself with responsive images and a placeholder', function () { $media = $this->testModelWithConversion ->addMedia($this->getTestJpg()) From a343dd9d85391253331a8d9087ac6b5c74da09c9 Mon Sep 17 00:00:00 2001 From: Quentin Date: Thu, 31 Mar 2022 08:58:02 +0200 Subject: [PATCH 3/3] Remove not matched phpstan ignoreErrors rules --- phpstan-baseline.neon | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 9d3fa2f86..96a7a50c0 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -135,11 +135,6 @@ parameters: count: 2 path: src/Conversions/ConversionCollection.php - - - message: "#^Access to an undefined property mixed\\:\\:\\$mediaConversions\\.$#" - count: 1 - path: src/Conversions/ConversionCollection.php - - message: "#^Method Spatie\\\\MediaLibrary\\\\Conversions\\\\ConversionCollection\\:\\:addManipulationToConversion\\(\\) has no return type specified\\.$#" count: 1 @@ -1495,11 +1490,6 @@ parameters: count: 1 path: src/MediaCollections/Models/Media.php - - - message: "#^Property Spatie\\\\MediaLibrary\\\\MediaCollections\\\\Models\\\\Media\\:\\:\\$casts type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/MediaCollections/Models/Media.php - - message: "#^Unable to resolve the template type TKey in call to function collect$#" count: 1