Skip to content

Commit d415d2f

Browse files
committed
MC-14970: HTML Code is not rendered on storefront for catalog category & products
- Add directive patterns to catalog output
1 parent 431f38c commit d415d2f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
*/
1313
class TemplatePlugin
1414
{
15-
const DATA_BACKGROUND_IMAGE = 'data-background-images';
15+
const BACKGROUND_IMAGE_PATTERN = '/data-background-images/si';
16+
17+
const HTML_CONTENT_TYPE_PATTERN = '/data-content-type="html"/si';
1618

1719
/**
1820
* @var \Magento\Framework\View\ConfigInterface
@@ -55,13 +57,13 @@ public function afterFilter(\Magento\Framework\Filter\Template $subject, string
5557
$this->domDocument = false;
5658

5759
// Validate if the filtered result requires background image processing
58-
if (strpos($result, self::DATA_BACKGROUND_IMAGE) !== false) {
60+
if (preg_match(self::BACKGROUND_IMAGE_PATTERN, $result)) {
5961
$document = $this->getDomDocument($result);
6062
$this->generateBackgroundImageStyles($document);
6163
}
6264

6365
// Process any HTML content types, they need to be decoded on the front-end
64-
if (strpos($result, 'data-content-type="html"') !== false) {
66+
if (preg_match(self::HTML_CONTENT_TYPE_PATTERN, $result)) {
6567
$document = $this->getDomDocument($result);
6668
$this->decodeHtmlContentTypes($document);
6769
}
@@ -164,10 +166,10 @@ private function decodeHtmlContentTypes(\DOMDocument $document): void
164166
private function generateBackgroundImageStyles(\DOMDocument $document) : void
165167
{
166168
$xpath = new \DOMXPath($document);
167-
$nodes = $xpath->query('//*[@' . self:: DATA_BACKGROUND_IMAGE . ']');
169+
$nodes = $xpath->query('//*[@data-background-images]');
168170
foreach ($nodes as $node) {
169171
/* @var \DOMElement $node */
170-
$backgroundImages = $node->attributes->getNamedItem(self:: DATA_BACKGROUND_IMAGE);
172+
$backgroundImages = $node->attributes->getNamedItem('data-background-images');
171173
if ($backgroundImages->nodeValue !== '') {
172174
$elementClass = uniqid('background-image-');
173175
$images = json_decode(stripslashes($backgroundImages->nodeValue), true);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,12 @@
132132
<argument name="productCollectionFactory" xsi:type="object">pageBuilderProductCollectionFactory</argument>
133133
</arguments>
134134
</type>
135+
<type name="Magento\Catalog\Helper\Output">
136+
<arguments>
137+
<argument name="directivePatterns" xsi:type="array">
138+
<item name="backgroundImage" xsi:type="const">\Magento\PageBuilder\Plugin\Filter\TemplatePlugin::BACKGROUND_IMAGE_PATTERN</item>
139+
<item name="htmlContentType" xsi:type="const">\Magento\PageBuilder\Plugin\Filter\TemplatePlugin::HTML_CONTENT_TYPE_PATTERN</item>
140+
</argument>
141+
</arguments>
142+
</type>
135143
</config>

0 commit comments

Comments
 (0)