14
14
use Magento \Framework \DB \DataConverter \DataConverterInterface ;
15
15
16
16
/**
17
- * ...
17
+ * Convert Inline Styles to Internal
18
18
*/
19
19
class PageBuilderStripStyles implements DataConverterInterface
20
20
{
@@ -35,12 +35,12 @@ public function __construct(DOMDocument $domDocument)
35
35
* Generates `mageUtils.uniqueid()` Naming Convention
36
36
*
37
37
* @param int $length
38
- * @param string $prefix
39
38
* @return string
39
+ * @todo Refactor `$length` Param
40
40
*/
41
- private function generateDataAttribute (int $ length = 7 , string $ prefix = ' style- ' ): string
41
+ private function generateDataAttribute (int $ length = 7 ): string
42
42
{
43
- return $ prefix . substr ( strtoupper (uniqid ()), 0 , $ length ); // @todo: Fix RNGesus...
43
+ return strtoupper (uniqid ());
44
44
}
45
45
46
46
/**
@@ -54,9 +54,8 @@ private function generateInternalStyles(array $styleMap): string
54
54
$ output = '' ;
55
55
56
56
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 . '} ' ;
60
59
}
61
60
62
61
return $ output ;
@@ -70,6 +69,8 @@ public function convert($value)
70
69
$ document = new DOMDocument ();
71
70
$ document ->loadHTML ($ value );
72
71
$ xpath = new DOMXPath ($ document );
72
+
73
+ $ body = $ document ->documentElement ->lastChild ;
73
74
$ nodes = $ xpath ->query ('//*[@style] ' ); // Query for Inline Styles
74
75
$ styleMap = [];
75
76
@@ -79,7 +80,7 @@ public function convert($value)
79
80
80
81
if ($ styleAttr ) {
81
82
$ generatedDataAttribute = $ this ->generateDataAttribute ();
82
- $ node ->setAttribute ('data-pb-style ' , $ this -> generateDataAttribute () );
83
+ $ node ->setAttribute ('data-pb-style ' , $ generatedDataAttribute );
83
84
$ styleMap [$ generatedDataAttribute ] = $ styleAttr ; // Amend Array for Internal Style Generation
84
85
$ node ->removeAttribute ('style ' );
85
86
}
@@ -90,7 +91,7 @@ public function convert($value)
90
91
'style ' ,
91
92
$ this ->generateInternalStyles ($ styleMap )
92
93
);
93
- $ xpath -> query ( ' // body' )[ 0 ] ->appendChild ($ style ); // @todo: Refactor
94
+ $ body ->appendChild ($ style );
94
95
95
96
// @todo: Refactor
96
97
preg_match (
0 commit comments