Skip to content

Commit 50a0904

Browse files
committed
MC-13917: Content types mark up within Text content type causes whole stage to become HTML
- Resolve issue with content types containing other content types incorrectly
1 parent 6c806ef commit 50a0904

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/master-format/read/configurable.js

Lines changed: 15 additions & 5 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/stage-builder.js

Lines changed: 6 additions & 3 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/ts/js/master-format/read/configurable.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class Configurable implements ReadInterface {
4141
let data = {};
4242
for (const elementName of Object.keys(config.elements)) {
4343
const elementConfig = config.elements[elementName];
44-
const currentElement = this.findElementByName(element, elementName);
44+
const currentElement = this.findElementByName(role, element, elementName);
4545

4646
// If we cannot locate the current element skip trying to read any attributes from it
4747
if (currentElement === null || currentElement === undefined) {
@@ -93,20 +93,26 @@ export default class Configurable implements ReadInterface {
9393
* Find the element for the current content type by it's name, avoiding searching in other content types by
9494
* removing any other element which contains it's own data-role.
9595
*
96+
* @param {string} role
9697
* @param {HTMLElement} element
9798
* @param {string} name
9899
* @returns {HTMLElement}
99100
*/
100-
private findElementByName(element: HTMLElement, name: string): HTMLElement {
101+
private findElementByName(role: string, element: HTMLElement, name: string): HTMLElement {
101102
// Create a clone of the element to avoid modifying the source
102103
const currentElement = $(element).clone();
103-
// Remove all child instances of data-role elements
104-
currentElement.find(`[${Config.getConfig("dataRoleAttributeName")}]`).remove();
104+
if (currentElement.attr("data-element") === name) {
105+
return currentElement[0];
106+
}
107+
108+
// Attempt to find the element in the children of the data-role
109+
const searchInChildren = currentElement.find(`[data-element="${name}"]`);
110+
// Ensure the element is within the current content type
111+
if (searchInChildren.length > 0 && searchInChildren.closest("[data-role]")[0] === currentElement[0]) {
112+
return searchInChildren[0];
113+
}
105114

106-
// Attempt to find the content type element within the modified clone element
107-
return currentElement.attr("data-element") === name
108-
? currentElement[0]
109-
: currentElement[0].querySelector<HTMLElement>(`[data-element=${name}]`);
115+
return null;
110116
}
111117

112118
/**

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/stage-builder.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import validateFormat from "./master-format/validator";
2020
import Stage from "./stage";
2121
import {removeQuotesInMediaDirectives} from "./utils/directives";
2222
import {set} from "./utils/object";
23+
import ContentTypeCollection from "./content-type-collection";
2324

2425
/**
2526
* Build the stage with the provided value
@@ -62,7 +63,10 @@ function buildElementIntoStage(element: Element, parent: ContentTypeCollectionIn
6263
return Promise.all(childPromises).then((childrenPromises) => {
6364
return Promise.all(childrenPromises.map((child, index) => {
6465
parent.addChild(child);
65-
return buildElementIntoStage(childElements[index], child, stage);
66+
// Only render children if the content type implements the collection
67+
if (child instanceof ContentTypeCollection) {
68+
return buildElementIntoStage(childElements[index], child, stage);
69+
}
6670
}));
6771
});
6872
}

0 commit comments

Comments
 (0)