Skip to content

Commit 1e7b674

Browse files
committed
#558: Content Types Output Style Attribute Removal
- Minor Refactoring
1 parent 3790cc3 commit 1e7b674

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

app/code/Magento/PageBuilder/Setup/Converters/PageBuilderStripStyles.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\Framework\DB\DataConverter\DataConverterInterface;
1515

1616
/**
17-
* ...
17+
* Convert Inline Styles to Internal
1818
*/
1919
class PageBuilderStripStyles implements DataConverterInterface
2020
{
@@ -35,12 +35,12 @@ public function __construct(DOMDocument $domDocument)
3535
* Generates `mageUtils.uniqueid()` Naming Convention
3636
*
3737
* @param int $length
38-
* @param string $prefix
3938
* @return string
39+
* @todo Refactor `$length` Param
4040
*/
41-
private function generateDataAttribute(int $length = 7, string $prefix = 'style-'): string
41+
private function generateDataAttribute(int $length = 7): string
4242
{
43-
return $prefix . substr(strtoupper(uniqid()), 0, $length); // @todo: Fix RNGesus...
43+
return strtoupper(uniqid());
4444
}
4545

4646
/**
@@ -54,9 +54,8 @@ private function generateInternalStyles(array $styleMap): string
5454
$output = '';
5555

5656
foreach ($styleMap as $selector => $styles) {
57-
$output .= '[data-pb-style="' . $selector . '"] { ';
58-
$output .= $styles;
59-
$output .= ' }';
57+
$output .= '[data-pb-style="' . $selector . '"]';
58+
$output .= '{' . $styles . '}';
6059
}
6160

6261
return $output;
@@ -70,6 +69,8 @@ public function convert($value)
7069
$document = new DOMDocument();
7170
$document->loadHTML($value);
7271
$xpath = new DOMXPath($document);
72+
73+
$body = $document->documentElement->lastChild;
7374
$nodes = $xpath->query('//*[@style]'); // Query for Inline Styles
7475
$styleMap = [];
7576

@@ -79,7 +80,7 @@ public function convert($value)
7980

8081
if ($styleAttr) {
8182
$generatedDataAttribute = $this->generateDataAttribute();
82-
$node->setAttribute('data-pb-style', $this->generateDataAttribute());
83+
$node->setAttribute('data-pb-style', $generatedDataAttribute);
8384
$styleMap[$generatedDataAttribute] = $styleAttr; // Amend Array for Internal Style Generation
8485
$node->removeAttribute('style');
8586
}
@@ -90,7 +91,7 @@ public function convert($value)
9091
'style',
9192
$this->generateInternalStyles($styleMap)
9293
);
93-
$xpath->query('//body')[0]->appendChild($style); // @todo: Refactor
94+
$body->appendChild($style);
9495

9596
// @todo: Refactor
9697
preg_match(

0 commit comments

Comments
 (0)