Skip to content

Commit 5a95c9a

Browse files
author
Michael Yu
committed
MC-518: Simplify mapping of content type
- Removed data-element from configuration - Updated observable updater to add in data-element
1 parent 292109e commit 5a95c9a

File tree

29 files changed

+6
-242
lines changed

29 files changed

+6
-242
lines changed

app/code/Magento/PageBuilder/docs/content-type-configuration.md

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ The following is an example of a content type configuration in `view/adminhtml/p
110110
<complex_property name="margins_and_padding" reader="Magento_PageBuilder/js/property/margins" converter="Magento_PageBuilder/js/converter/style/margins"/>
111111
</style_properties>
112112
<attributes>
113-
<attribute name="element" source="data-element"/>
114113
<attribute name="name" source="data-role"/>
115114
<attribute name="appearance" source="data-appearance"/>
116115
<attribute name="show_button" source="data-show-button"/>
@@ -120,7 +119,6 @@ The following is an example of a content type configuration in `view/adminhtml/p
120119
</element>
121120
<element name="link">
122121
<attributes>
123-
<attribute name="element" source="data-element"/>
124122
<complex_attribute name="link_url" reader="Magento_PageBuilder/js/property/link" persist="false"/>
125123
<attribute name="link_url" source="href" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-href" />
126124
<attribute name="link_url" source="target" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-target" />
@@ -134,7 +132,6 @@ The following is an example of a content type configuration in `view/adminhtml/p
134132
<complex_property name="margins_and_padding" reader="Magento_PageBuilder/js/property/paddings" converter="Magento_PageBuilder/js/converter/style/paddings"/>
135133
</style_properties>
136134
<attributes>
137-
<attribute name="element" source="data-element"/>
138135
<attribute name="overlay_color" source="data-overlay-color" persist="false" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-color"/>
139136
<attribute name="overlay_transparency" source="data-overlay-color" persist="false" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-transparency"/>
140137
<attribute name="overlay_transparency" source="data-overlay-color" virtual="true" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-color-transparency"/>
@@ -150,9 +147,6 @@ The following is an example of a content type configuration in `view/adminhtml/p
150147
<property name="background_repeat" source="background_repeat" converter="Magento_PageBuilder/js/converter/style/background-repeat"/>
151148
<property name="background_attachment" source="background_attachment"/>
152149
</style_properties>
153-
<attributes>
154-
<attribute name="element" source="data-element"/>
155-
</attributes>
156150
</element>
157151
<element name="mobile_image">
158152
<style_properties>
@@ -164,24 +158,15 @@ The following is an example of a content type configuration in `view/adminhtml/p
164158
<property name="background_repeat" source="background_repeat" converter="Magento_PageBuilder/js/converter/style/background-repeat"/>
165159
<property name="background_attachment" source="background_attachment"/>
166160
</style_properties>
167-
<attributes>
168-
<attribute name="element" source="data-element"/>
169-
</attributes>
170161
</element>
171162
<element name="content">
172-
<attributes>
173-
<attribute name="element" source="data-element"/>
174-
</attributes>
175-
<html name="message"/>
163+
<html name="message"/>
176164
</element>
177165
<element name="button">
178166
<style_properties>
179167
<property name="opacity" source="opacity" virtual="true" converter="Magento_PageBuilder/js/converter/banner/style/button-opacity"/>
180168
<property name="visibility" source="visibility" virtual="true" converter="Magento_PageBuilder/js/converter/banner/style/button-visibility"/>
181169
</style_properties>
182-
<attributes>
183-
<attribute name="element" source="data-element"/>
184-
</attributes>
185170
<html name="button_text"/>
186171
<css name="button_type">
187172
<filter>
@@ -321,14 +306,12 @@ Set the `default` attribute to "true" in an `appearance` node to set the default
321306
<complex_property name="margins_and_padding" reader="Magento_PageBuilder/js/property/margins" converter="Magento_PageBuilder/js/converter/style/margins"/>
322307
</style_properties>
323308
<attributes>
324-
<attribute name="element" source="data-element"/>
325309
<attribute name="name" source="data-role"/>
326310
</attributes>
327311
<css name="css_classes"/>
328312
</element>
329313
<element name="link">
330314
<attributes>
331-
<attribute name="element" source="data-element"/>
332315
<complex_attribute name="link_url" reader="Magento_PageBuilder/js/property/link" persist="false"/>
333316
<attribute name="link_url" source="href" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-href" />
334317
<attribute name="link_url" source="target" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-target" />
@@ -337,7 +320,6 @@ Set the `default` attribute to "true" in an `appearance` node to set the default
337320
</element>
338321
<element name="overlay">
339322
<attributes>
340-
<attribute name="element" source="data-element"/>
341323
<attribute name="overlay_color" source="data-overlay-color" persist="false" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-color"/>
342324
<attribute name="overlay_transparency" source="data-overlay-color" persist="false" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-transparency"/>
343325
<attribute name="overlay_transparency" source="data-overlay-color" virtual="true" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-color-transparency"/>
@@ -347,32 +329,20 @@ Set the `default` attribute to "true" in an `appearance` node to set the default
347329
<style_properties>
348330
<property name="background_image" source="background_image" converter="Magento_PageBuilder/js/converter/style/background-image" preview_converter="Magento_PageBuilder/js/converter/style/preview/background-image"/>
349331
</style_properties>
350-
<attributes>
351-
<attribute name="element" source="data-element"/>
352-
</attributes>
353332
</element>
354333
<element name="mobile_image">
355334
<style_properties>
356335
<property name="mobile_image" source="background_image" converter="Magento_PageBuilder/js/converter/style/background-image" preview_converter="Magento_PageBuilder/js/converter/style/preview/background-image"/>
357336
</style_properties>
358-
<attributes>
359-
<attribute name="element" source="data-element"/>
360-
</attributes>
361337
</element>
362338
<element name="content">
363-
<attributes>
364-
<attribute name="element" source="data-element"/>
365-
</attributes>
366339
<html name="message"/>
367340
</element>
368341
<element name="button">
369342
<style_properties>
370343
<property name="opacity" source="opacity" virtual="true" converter="Magento_PageBuilder/js/converter/banner/style/button-opacity"/>
371344
<property name="visibility" source="visibility" virtual="true" converter="Magento_PageBuilder/js/converter/banner/style/button-visibility"/>
372345
</style_properties>
373-
<attributes>
374-
<attribute name="element" source="data-element"/>
375-
</attributes>
376346
<html name="button_text"/>
377347
<css name="button_type">
378348
<filter>
@@ -391,12 +361,6 @@ Set the `default` attribute to "true" in an `appearance` node to set the default
391361
</converters>
392362
```
393363

394-
### Requirement for every `element`
395-
Every element must have an `element` attribute sourced to `data-element` in order for the reader to read correctly from master format.
396-
``` xml
397-
<attribute name="element" source="data-element"/>
398-
```
399-
400364
### Attributes for `property` and `attribute`
401365

402366
| Attribute | Description |
@@ -428,9 +392,6 @@ Every element must have an `element` attribute sourced to `data-element` in orde
428392
<static_property source="max-width" value="100%"/>
429393
<static_property source="height" value="auto"/>
430394
</style_properties>
431-
<attributes>
432-
<attribute name="element" source="data-element"/>
433-
</attributes>
434395
</element>
435396
```
436397

app/code/Magento/PageBuilder/docs/how-to-add-new-content-type.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ To add configuration for a new content type, create a file under the following l
9090
<complex_property name="margins_and_padding" reader="Magento_PageBuilder/js/property/paddings" converter="Magento_PageBuilder/js/converter/style/paddings"/>
9191
</style_properties>
9292
<attributes>
93-
<attribute name="element" source="data-element"/>
9493
<attribute name="name" source="data-role"/>
9594
</attributes>
9695
<css name="css_classes"/>
@@ -296,7 +295,6 @@ Now, let's add content type that can contain other content types. Create configu
296295
<complex_property name="margins_and_padding" reader="Magento_PageBuilder/js/property/paddings" converter="Magento_PageBuilder/js/converter/style/paddings"/>
297296
</style_properties>
298297
<attributes>
299-
<attribute name="element" source="data-element"/>
300298
<attribute name="name" source="data-role"/>
301299
</attributes>
302300
<css name="css_classes"/>

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/observable-updater.js

Lines changed: 1 addition & 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/ts/js/content-type/observable-updater.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,23 @@ export default class ObservableUpdater {
104104
* @deprecated
105105
*/
106106
public convertAttributes(config: any, data: DataObject) {
107-
const result = {};
107+
const result: any = {};
108108
for (const attributeConfig of config.attributes) {
109109
if (undefined !== attributeConfig.persist
110110
&& null !== attributeConfig.persist
111111
&& "false" === attributeConfig.persist
112112
) {
113113
continue;
114114
}
115-
if (attributeConfig.var === "element") {
116-
result[attributeConfig.name] = config.element;
117-
continue;
118-
}
119115
let value = data[attributeConfig.var];
120116
const converter = this.converterResolver(attributeConfig);
121117
if (this.converterPool.get(converter)) {
122118
value = this.converterPool.get(converter).toDom(attributeConfig.var, data);
123119
}
124120
result[attributeConfig.name] = value;
125121
}
122+
result["data-element"] = config.element;
123+
126124
return result;
127125
}
128126

app/code/Magento/PageBuilder/view/base/pagebuilder/content_type/anchor.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
<complex_property name="margins_and_padding" reader="Magento_PageBuilder/js/property/paddings" converter="Magento_PageBuilder/js/converter/style/paddings"/>
4040
</style_properties>
4141
<attributes>
42-
<attribute name="element" source="data-element"/>
4342
<attribute name="name" source="data-role"/>
4443
<attribute name="appearance" source="data-appearance"/>
4544
<attribute name="id" source="id"/>

0 commit comments

Comments
 (0)