Skip to content

Commit 0ee4cfb

Browse files
author
Eric Homanchuk
committed
Add fallback image
1 parent 8948dcb commit 0ee4cfb

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/TwigMainspringExtension.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,26 @@ public function responsiveImageStyle($layout, $section_layout, $image_style, $zo
101101
}
102102
}
103103

104-
$responsive_image_style = '';
104+
// If layout or section_layout are empty then this probably means that the
105+
// paragraph has been added to a new section on node edit that has not been
106+
// saved. Since the layout section has not been created yet the information
107+
// is not available to te paragraph so we need to just default to the
108+
// largest possible image sizes. This is defined in the
109+
// theme.responsive_image_layouts.yml as the fallback option.
110+
if (empty($layout) || empty($section_layout)) {
111+
$layout = key($data['fallback']);
112+
$section_layout = $data['fallback'][$layout];
113+
}
105114

115+
// Used to store the responsive image style that is determined from checking
116+
// the theme.responsive_image_layouts.yml file in the theme.
117+
$responsive_image_style = '';
118+
// If we can find a matching responsive image style in the file.
106119
if (isset($data[$layout][$section_layout][$image_style])) {
107120
$option = $data[$layout][$section_layout][$image_style];
121+
// If the option is an array it means that this is multiple columns and
122+
// the zone should be used to figure out what array index is the correct
123+
// image style.
108124
if (is_array($option)) {
109125
if (!empty($zone)) {
110126
$n = trim($zone, 'zone');

0 commit comments

Comments
 (0)