From dc4adb0958846f06da2bb53fa37c365cb2bd9605 Mon Sep 17 00:00:00 2001 From: Sebastian Thulin Date: Wed, 2 Oct 2024 11:49:47 +0200 Subject: [PATCH] feat: implement image contract in manual input views card, block. --- source/php/Module/ManualInput/ManualInput.php | 30 ++++++++++++++----- .../views/appearances/card.blade.php | 1 - 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/source/php/Module/ManualInput/ManualInput.php b/source/php/Module/ManualInput/ManualInput.php index 1e7fdded1..1391f8054 100644 --- a/source/php/Module/ManualInput/ManualInput.php +++ b/source/php/Module/ManualInput/ManualInput.php @@ -65,10 +65,13 @@ public function data(): array } private function maybeGetImageImageContract(string $displayAs, int $imageId) { - if (in_array($displayAs, ['segment'])) { + + $width = $this->getImageSize($displayAs, 'width'); + + if (in_array($displayAs, ['segment', 'block', 'card'])) { return ImageComponentContract::factory( $imageId, - [1920, false], + [$width, false], new ImageResolver() ); } @@ -189,6 +192,9 @@ private function getImageData($imageId = false, $size = [400, 225]) $image['removeCaption'] = true; } + unset($image['title']); + unset($image['description']); + return $image; } @@ -201,18 +207,28 @@ private function getImageData($imageId = false, $size = [400, 225]) * @param string $displayAs The name of the template/view. * @return array */ - private function getImageSize($displayAs) { + private function getImageSize($displayAs, $return = "both"): null|array|int { switch ($displayAs) { case "segment": - return [800, 550]; + $dimensions = [1920, 1080]; case "block": - return [500, 500]; + $dimensions = [1024, 1024]; case "collection": case "box": - return [300, 300]; + $dimensions = [768, 768]; default: - return [400, 225]; + $dimensions = [1440, 810]; + } + + if($return == "width") { + return $dimensions[0] ?? null; + } + + if($return == "height") { + return $dimensions[1] ?? null; } + + return $dimensions; } /** diff --git a/source/php/Module/ManualInput/views/appearances/card.blade.php b/source/php/Module/ManualInput/views/appearances/card.blade.php index 01e462436..6273f8dec 100644 --- a/source/php/Module/ManualInput/views/appearances/card.blade.php +++ b/source/php/Module/ManualInput/views/appearances/card.blade.php @@ -5,7 +5,6 @@ 'context' => $context, 'content' => $input['content'], 'image' => $input['image'], - 'imageFirst' => true, 'containerAware' => true, 'classList' => ['u-height--100'] ])