Skip to content

Commit

Permalink
feat: add image contract to segment cards in lists. (#671)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Thulin <sebastian.thulin@helsingborg.se>
  • Loading branch information
sebastianthulin and Sebastian Thulin authored Sep 25, 2024
1 parent 97efe3b commit b0f32da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion source/php/Module/ManualInput/ManualInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

use Municipio\Helper\Image as ImageHelper;

use Modularity\Integrations\Component\ImageResolver;
use Modularity\Integrations\Component\ImageFocusResolver;
use ComponentLibrary\Integrations\Image\Image as ImageComponentContract;

class ManualInput extends \Modularity\Module
{
public $slug = 'manualinput';
Expand Down Expand Up @@ -48,7 +52,7 @@ public function data(): array
});
$arr = array_merge($this->getManualInputDefaultValues(), $input);
$arr['isHighlighted'] = $this->canBeHighlighted($fields, $index);
$arr['image'] = $this->getImageData($arr['image'], $imageSize);
$arr['image'] = $this->maybeGetImageImageContract($displayAs, $arr['image']) ?? $this->getImageData($arr['image'], $imageSize);
$arr['accordion_column_values'] = $this->createAccordionTitles($arr['accordion_column_values'], $arr['title']);
$arr['view'] = $this->getInputView($arr['isHighlighted']);
$arr['columnSize'] = $this->getInputColumnSize($fields, $arr['isHighlighted']);
Expand All @@ -60,6 +64,18 @@ public function data(): array
return $data;
}

private function maybeGetImageImageContract(string $displayAs, int $imageId) {
if (in_array($displayAs, ['segment'])) {
return ImageComponentContract::factory(
$imageId,
[1920, false],
new ImageResolver()
);
}

return null;
}

/**
* @return array Array with default values
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'layout' => 'card',
'title' => $input['title'],
'context' => $context,
'image' => $input['image']['src'],
'image' => $input['image'],
'content' => $input['content'],
'buttons' => [['text' => $input['linkText'], 'href' => $input['link'], 'color' => 'primary']],
'containerAware' => true,
Expand Down

0 comments on commit b0f32da

Please sign in to comment.