Skip to content

Commit 2f5e019

Browse files
committed
#558: Content Types Output Style Attribute Removal
- Adding Converter to Remove `style` Attribute(s) from Page Builder
1 parent 91c59fb commit 2f5e019

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types = 1);
8+
9+
namespace Magento\PageBuilder\Setup\Converters;
10+
11+
use Magento\Framework\DB\DataConverter\DataConverterInterface;
12+
use Magento\PageBuilder\Model\Dom\Adapter\ElementInterface;
13+
use Magento\PageBuilder\Model\Dom\HtmlDocumentFactory;
14+
15+
/**
16+
* ...
17+
*/
18+
class PageBuilderStripStyles implements DataConverterInterface
19+
{
20+
/**
21+
* @var HtmlDocumentFactory
22+
*/
23+
private $htmlDocumentFactory;
24+
25+
/**
26+
* @param HtmlDocumentFactory $htmlDocumentFactory
27+
*/
28+
public function __construct(HtmlDocumentFactory $htmlDocumentFactory)
29+
{
30+
$this->htmlDocumentFactory = $htmlDocumentFactory;
31+
}
32+
33+
/**
34+
* @inheritDoc
35+
*/
36+
public function convert($value)
37+
{
38+
$document = $this->htmlDocumentFactory->create(['document' => $value]);
39+
$queryPageBuilderElements = $document->querySelectorAll('[style]'); // @todo: Match Types
40+
41+
/** @var ElementInterface $element */
42+
foreach ($queryPageBuilderElements as $element) {
43+
$style = $element->getAttribute('style');
44+
45+
if ($style) {
46+
// @todo: Convert to Inline
47+
48+
$element->removeAttribute('style');
49+
}
50+
}
51+
52+
return $queryPageBuilderElements->count() > 0 ? $document->stripHtmlWrapperTags() : $value;
53+
}
54+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types = 1);
8+
9+
namespace Magento\PageBuilder\Setup\Patch\Data;
10+
11+
use Magento\Framework\DB\FieldDataConversionException;
12+
use Magento\Framework\Setup\Patch\DataPatchInterface;
13+
use Magento\PageBuilder\Setup\Converters\PageBuilderStripStyles;
14+
use Magento\PageBuilder\Setup\UpgradeContentHelper;
15+
16+
/**
17+
* ...
18+
*/
19+
class UpgradePageBuilderStripStyles implements DataPatchInterface
20+
{
21+
/**
22+
* @var UpgradeContentHelper
23+
*/
24+
private $helper;
25+
26+
/**
27+
* @param UpgradeContentHelper $helper
28+
*/
29+
public function __construct(
30+
UpgradeContentHelper $helper
31+
) {
32+
$this->helper = $helper;
33+
}
34+
35+
/**
36+
* Upgrade
37+
*
38+
* @return void
39+
* @throws FieldDataConversionException
40+
*/
41+
public function apply()
42+
{
43+
$this->helper->upgrade([
44+
PageBuilderStripStyles::class
45+
]);
46+
}
47+
48+
/**
49+
* @inheritdoc
50+
*/
51+
public function getAliases()
52+
{
53+
return [];
54+
}
55+
56+
/**
57+
* @inheritdoc
58+
*/
59+
public static function getDependencies()
60+
{
61+
return [];
62+
}
63+
}

0 commit comments

Comments
 (0)