Skip to content

Commit

Permalink
feat: implement image contract in manual input views card, block.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thulin committed Oct 2, 2024
1 parent e1aba77 commit dc4adb0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
30 changes: 23 additions & 7 deletions source/php/Module/ManualInput/ManualInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
Expand Down Expand Up @@ -189,6 +192,9 @@ private function getImageData($imageId = false, $size = [400, 225])
$image['removeCaption'] = true;
}

unset($image['title']);
unset($image['description']);

return $image;
}

Expand All @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
'context' => $context,
'content' => $input['content'],
'image' => $input['image'],
'imageFirst' => true,
'containerAware' => true,
'classList' => ['u-height--100']
])
Expand Down

0 comments on commit dc4adb0

Please sign in to comment.