Skip to content

Commit aeea24a

Browse files
Add responsive image formatter build
1 parent 7464b0c commit aeea24a

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/TwigMainspringExtension.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function __construct(ThemeHandlerInterface $theme_handler, MessengerInter
7070
public function getFunctions(): array {
7171
$functions = [
7272
new TwigFunction('mainspring_responsive_image_style', [$this, 'responsiveImageStyle']),
73+
new TwigFunction('mainspring_responsive_image', [$this, 'responsiveImage']),
7374
];
7475

7576
return $functions;
@@ -153,4 +154,26 @@ public function responsiveImageStyle($layout, $section_layout, $image_style, $zo
153154
return $responsive_image_style;
154155
}
155156

157+
/**
158+
* Creates a responsive image.
159+
*
160+
* @param mixed $image
161+
* The image field.
162+
* @param string $responsive_image_style
163+
* The responsive image style.
164+
* @param array $image_attributes
165+
* The image field attributes.
166+
*
167+
* @return array
168+
* The responsive image formatter render array.
169+
*/
170+
public function responsiveImage($image, $responsive_image_style, array $image_attributes = []) {
171+
return [
172+
'#theme' => 'responsive_image_formatter',
173+
'#item' => $image,
174+
'#item_attributes' => $image_attributes,
175+
'#responsive_image_style_id' => $responsive_image_style,
176+
];
177+
}
178+
156179
}

0 commit comments

Comments
 (0)