diff --git a/src/View/Helper/PosterHelper.php b/src/View/Helper/PosterHelper.php index 658c718..2719068 100644 --- a/src/View/Helper/PosterHelper.php +++ b/src/View/Helper/PosterHelper.php @@ -165,9 +165,9 @@ public function sourceSet(ObjectEntity|null $object, array|string|false $thumbOp } $url = $this->url($variant, $thumbOptions, $posterOptions); - $width = $this->getStreamWidth($variant); + $slotWidth = $this->getSlotWidth($variant); - return sprintf('%s %sw, %s %sw', $url, $width, $fallbackUrl, $fallbackWidth); + return sprintf('%s %sw, %s %sw', $url, $slotWidth, $fallbackUrl, $fallbackWidth); } /** @@ -182,6 +182,17 @@ protected function getStreamWidth(Media $media): int return Hash::get($media, 'streams.0.width', $this->getConfig('PosterMobile.slotWidth', static::MOBILE_DEFAULT_WIDTH)); } + /** + * Get the slot width of a media object. + * + * @param \BEdita\Core\Model\Entity\Media $variant Media entity. + * @return int + */ + protected function getSlotWidth(Media $variant): int + { + return Hash::get($variant ?? [], '_joinData.params.slot_width', $this->getConfig('PosterMobile.slotWidth', static::MOBILE_DEFAULT_WIDTH)); + } + /** * Get sizes attribute for image. * @@ -192,7 +203,7 @@ public function sizes(Media $poster): string { $variant = $this->mobile($poster); $maxWidth = $this->getConfig('PosterMobile.maxWidth', static::MOBILE_MAX_WIDTH); - $slotWidth = Hash::get($variant ?? [], '_joinData.params.slot_width', $this->getConfig('PosterMobile.slotWidth', static::MOBILE_DEFAULT_WIDTH)); + $slotWidth = $this->getSlotWidth($variant); return sprintf('(max-width: %spx) %spx', $maxWidth, $slotWidth); } diff --git a/tests/TestCase/View/Helper/PosterHelperTest.php b/tests/TestCase/View/Helper/PosterHelperTest.php index 0468ec5..d8df78d 100644 --- a/tests/TestCase/View/Helper/PosterHelperTest.php +++ b/tests/TestCase/View/Helper/PosterHelperTest.php @@ -204,7 +204,7 @@ public function testSourceSet() // no variant $this->assertSame('https://www.bedita.com/first.png 1500w', $this->Poster->sourceSet($image)); - $this->setVariantProviderThumbnail($image, 640, 480); + $this->setVariantProviderThumbnail($image, 2000, 480); // variant available $this->assertSame('https://www.bedita.com/favicon.png 640w, https://www.bedita.com/first.png 1500w', $this->Poster->sourceSet($image)); @@ -219,7 +219,7 @@ public function testSourceSet() public function testSizes() { $image = $this->createImage(1500, 1000); - $this->setVariantProviderThumbnail($image, 640, 480); + $this->setVariantProviderThumbnail($image, 2000, 480); // no slot_width set, using image width $this->assertSame('(max-width: 767px) 640px', $this->Poster->sizes($image));