|
12 | 12 | */
|
13 | 13 | class TemplatePlugin
|
14 | 14 | {
|
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'; |
16 | 18 |
|
17 | 19 | /**
|
18 | 20 | * @var \Magento\Framework\View\ConfigInterface
|
@@ -55,13 +57,13 @@ public function afterFilter(\Magento\Framework\Filter\Template $subject, string
|
55 | 57 | $this->domDocument = false;
|
56 | 58 |
|
57 | 59 | // 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)) { |
59 | 61 | $document = $this->getDomDocument($result);
|
60 | 62 | $this->generateBackgroundImageStyles($document);
|
61 | 63 | }
|
62 | 64 |
|
63 | 65 | // 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)) { |
65 | 67 | $document = $this->getDomDocument($result);
|
66 | 68 | $this->decodeHtmlContentTypes($document);
|
67 | 69 | }
|
@@ -164,10 +166,10 @@ private function decodeHtmlContentTypes(\DOMDocument $document): void
|
164 | 166 | private function generateBackgroundImageStyles(\DOMDocument $document) : void
|
165 | 167 | {
|
166 | 168 | $xpath = new \DOMXPath($document);
|
167 |
| - $nodes = $xpath->query('//*[@' . self:: DATA_BACKGROUND_IMAGE . ']'); |
| 169 | + $nodes = $xpath->query('//*[@data-background-images]'); |
168 | 170 | foreach ($nodes as $node) {
|
169 | 171 | /* @var \DOMElement $node */
|
170 |
| - $backgroundImages = $node->attributes->getNamedItem(self:: DATA_BACKGROUND_IMAGE); |
| 172 | + $backgroundImages = $node->attributes->getNamedItem('data-background-images'); |
171 | 173 | if ($backgroundImages->nodeValue !== '') {
|
172 | 174 | $elementClass = uniqid('background-image-');
|
173 | 175 | $images = json_decode(stripslashes($backgroundImages->nodeValue), true);
|
|
0 commit comments