Skip to content

Commit dfd463e

Browse files
committed
ACP2E-1362: The issue is with Pagebuilder not being able to update/save text on certain pagebuilder pages.
1 parent d52a3e8 commit dfd463e

File tree

10 files changed

+128
-11
lines changed

10 files changed

+128
-11
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,18 @@
549549
<argument name="data" xsi:type="array">
550550
<item name="root_content_type" xsi:type="string">none</item>
551551
<item name="html_display_content_type" xsi:type="string">html</item>
552+
<item name="html_display_content_type" xsi:type="string">html</item>
552553
<item name="template_types" xsi:type="array">
553554
<item name="any" xsi:type="string">Any</item>
554555
<item name="page" xsi:type="string">Page</item>
555556
<item name="product" xsi:type="string">Product</item>
556557
<item name="category" xsi:type="string">Category</item>
557558
<item name="block" xsi:type="string">Block</item>
558559
</item>
560+
<item name="reserved_html_attributes" xsi:type="array">
561+
<item name="data-content-type" xsi:type="string">data-content-type</item>
562+
<item name="contenteditable" xsi:type="string">contenteditable</item>
563+
</item>
559564
</argument>
560565
<argument name="rootContainerConfig" xsi:type="array">
561566
<item name="label" xsi:type="string">Root Container</item>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@
414414
<item name="data-video-overlay-color" xsi:type="string">data-video-overlay-color</item>
415415
<item name="data-video-play-only-visible" xsi:type="string">data-video-play-only-visible</item>
416416
<item name="data-video-src" xsi:type="string">data-video-src</item>
417+
<item name="data-placeholder" xsi:type="string">data-placeholder</item>
417418
<item name="href" xsi:type="string">href</item>
418419
<item name="id" xsi:type="string">id</item>
419420
<item name="role" xsi:type="string">role</item>

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/banner/preview.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/slide/preview.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/text/preview.js

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/utils/editor.js

Lines changed: 40 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/banner/preview.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
isWysiwygSupported,
2525
lockImageSize,
2626
moveToBookmark,
27+
removeReservedHtmlAttributes,
2728
unlockImageSize,
2829
} from "../../utils/editor";
2930
import nestingLinkDialog from "../../utils/nesting-link-dialog";
@@ -493,6 +494,14 @@ export default class Preview extends BasePreview {
493494
* @inheritDoc
494495
*/
495496
protected bindEvents() {
497+
this.contentType.dataStore.subscribe((state: DataObject) => {
498+
const sanitizedContent = removeReservedHtmlAttributes(state.message);
499+
500+
if (sanitizedContent !== state.message) {
501+
state.message = sanitizedContent;
502+
}
503+
}, "message");
504+
496505
super.bindEvents();
497506
events.on("banner:mountAfter", (args: ContentTypeReadyEventParamsInterface) => {
498507
if (args.id === this.contentType.id) {

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/slide/preview.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
isWysiwygSupported,
2626
lockImageSize,
2727
moveToBookmark,
28+
removeReservedHtmlAttributes,
2829
unlockImageSize,
2930
} from "../../utils/editor";
3031
import nestingLinkDialog from "../../utils/nesting-link-dialog";
@@ -488,6 +489,14 @@ export default class Preview extends BasePreview {
488489
* @inheritDoc
489490
*/
490491
protected bindEvents() {
492+
this.contentType.dataStore.subscribe((state: DataObject) => {
493+
const sanitizedContent = removeReservedHtmlAttributes(state.content);
494+
495+
if (sanitizedContent !== state.content) {
496+
state.content = sanitizedContent;
497+
}
498+
}, "content");
499+
491500
super.bindEvents();
492501

493502
events.on("slide:mountAfter", (args: ContentTypeReadyEventParamsInterface) => {

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/text/preview.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
isWysiwygSupported,
2121
lockImageSize,
2222
moveToBookmark,
23+
removeReservedHtmlAttributes,
2324
replaceDoubleQuoteWithSingleQuoteWithinVariableDirective,
2425
unlockImageSize,
2526
} from "../../utils/editor";
@@ -340,17 +341,19 @@ export default class Preview extends BasePreview {
340341
* Bind events
341342
*/
342343
protected bindEvents() {
343-
super.bindEvents();
344-
345344
this.contentType.dataStore.subscribe((state: DataObject) => {
346-
const sanitizedContent = replaceDoubleQuoteWithSingleQuoteWithinVariableDirective(
347-
escapeDoubleQuoteWithinWidgetDirective(state.content),
348-
);
345+
const sanitizedContent = removeReservedHtmlAttributes(
346+
replaceDoubleQuoteWithSingleQuoteWithinVariableDirective(
347+
escapeDoubleQuoteWithinWidgetDirective(state.content),
348+
),
349+
);
349350

350351
if (sanitizedContent !== state.content) {
351352
state.content = sanitizedContent;
352353
}
353-
});
354+
}, "content");
355+
356+
super.bindEvents();
354357

355358
// After drop of new content type open TinyMCE and focus
356359
events.on("text:dropAfter", (args: ContentTypeMountEventParamsInterface) => {

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/utils/editor.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,40 @@ export function replaceDoubleQuoteWithSingleQuoteWithinVariableDirective(content
469469
);
470470
}
471471

472+
/**
473+
* Remove Page Builder reserved html tag attributes from the content
474+
*
475+
* @param {string} content
476+
* @returns {string}
477+
*/
478+
export function removeReservedHtmlAttributes(content: string): string
479+
{
480+
const attributes: {[key: string]: string} = Config.getConfig("stage_config").reserved_html_attributes || {};
481+
for (const attribute of Object.keys(attributes)) {
482+
content = removeHtmlTagAttribute(content, attribute);
483+
}
484+
return content;
485+
}
486+
487+
/**
488+
* Remove attribute from html tags
489+
*
490+
* @param content
491+
* @param name
492+
*/
493+
function removeHtmlTagAttribute(content: string, name: string): string
494+
{
495+
if (typeof content === "string" && content.indexOf(`${name}=`) !== -1) {
496+
const html = new DOMParser().parseFromString(content, "text/html");
497+
const children = html.querySelectorAll("[" + name + "]");
498+
children.forEach((child: Element) => {
499+
child.removeAttribute(name);
500+
});
501+
content = html.body.innerHTML;
502+
}
503+
return content;
504+
}
505+
472506
interface IdBookmark {
473507
id: string;
474508
keep?: boolean;

0 commit comments

Comments
 (0)