Skip to content

Commit a130d5e

Browse files
committed
MC-3700: Create concept for background image style generation
- Update view.xml format to reflect Magento_Catalog
1 parent 3bae1ba commit a130d5e

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

app/code/Magento/PageBuilder/Plugin/Filter/TemplatePlugin.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ private function generateCssFromImages(string $elementClass, array $images) : st
131131
'background-image' => 'url(' . $images['desktop_image'] . ')',
132132
];
133133
}
134-
if (isset($images['mobile_image']) && $this->getMobileBreakpoint()) {
135-
$mediaQuery = '@media only screen and (max-width: ' . $this->getMobileBreakpoint() . ')';
136-
$css[$mediaQuery]['.' . $elementClass] = [
134+
if (isset($images['mobile_image']) && $this->getMobileMediaQuery()) {
135+
$css[$this->getMobileMediaQuery()]['.' . $elementClass] = [
137136
'background-image' => 'url(' . $images['mobile_image'] . ')',
138137
];
139138
}
@@ -163,13 +162,23 @@ private function cssFromArray(array $css) : string
163162
}
164163

165164
/**
166-
* Retrieve the mobile breakpoint from the view configuration
165+
* Generate the mobile media query from view configuration
167166
*
168167
* @return null|string
169168
*/
170-
private function getMobileBreakpoint() : ?string
169+
private function getMobileMediaQuery() : ?string
171170
{
172-
$breakpoints = $this->viewConfig->getViewConfig()->getVarValue('Magento_PageBuilder', 'breakpoints');
173-
return isset($breakpoints['mobile']) ? $breakpoints['mobile'] : null;
171+
$breakpoints = $this->viewConfig->getViewConfig()->getVarValue(
172+
'Magento_PageBuilder',
173+
'breakpoints/mobile/conditions'
174+
);
175+
if ($breakpoints && count($breakpoints) > 0) {
176+
$mobileBreakpoint = "@media only screen ";
177+
foreach ($breakpoints as $key => $value) {
178+
$mobileBreakpoint .= "and (" . $key . ": " . $value . ") ";
179+
}
180+
return rtrim($mobileBreakpoint);
181+
}
182+
return null;
174183
}
175184
}

app/code/Magento/PageBuilder/etc/view.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
</media>
2525
<vars module="Magento_PageBuilder">
2626
<var name="breakpoints">
27-
<var name="mobile">768px</var>
27+
<var name="mobile">
28+
<var name="conditions">
29+
<var name="max-width">768px</var>
30+
</var>
31+
</var>
2832
</var>
2933
</vars>
3034
</view>

0 commit comments

Comments
 (0)