Skip to content

Commit 7993fa8

Browse files
author
Michael Yu
committed
Merge remote-tracking branch 'origin/MC-2228-name-conflict-on-merge' into cms-team-2-sprint-12
2 parents 27985a5 + 6658bba commit 7993fa8

25 files changed

+182
-118
lines changed

app/code/Magento/PageBuilder/Model/Config/ContentType/Converter.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ private function convertProperties(\DOMElement $elementNode): array
264264
if ($propertiesNode) {
265265
foreach ($propertiesNode->getElementsByTagName('property') as $propertyNode) {
266266
$propertiesData[] = [
267-
'var' => $this->getAttributeValue($propertyNode, 'name'),
267+
'var' => $this->extractVariableName($propertyNode),
268268
'name' => $this->getAttributeValue($propertyNode, 'source'),
269269
'converter' => $this->getAttributeValue($propertyNode, 'converter'),
270270
'preview_converter' => $this->getAttributeValue($propertyNode, 'preview_converter'),
@@ -274,7 +274,7 @@ private function convertProperties(\DOMElement $elementNode): array
274274
}
275275
foreach ($propertiesNode->getElementsByTagName('complex_property') as $propertyNode) {
276276
$propertiesData[] = [
277-
'var' => $this->getAttributeValue($propertyNode, 'name'),
277+
'var' => $this->extractVariableName($propertyNode),
278278
'reader' => $this->getAttributeValue($propertyNode, 'reader'),
279279
'converter' => $this->getAttributeValue($propertyNode, 'converter'),
280280
'preview_converter' => $this->getAttributeValue($propertyNode, 'preview_converter'),
@@ -306,7 +306,7 @@ private function convertAttributes(\DOMElement $elementNode): array
306306
if ($attributesNode) {
307307
foreach ($attributesNode->getElementsByTagName('attribute') as $attributeNode) {
308308
$attributesData[] = [
309-
'var' => $this->getAttributeValue($attributeNode, 'name'),
309+
'var' => $this->extractVariableName($attributeNode),
310310
'name' => $this->getAttributeValue($attributeNode, 'source'),
311311
'converter' => $this->getAttributeValue($attributeNode, 'converter'),
312312
'preview_converter' => $this->getAttributeValue($attributeNode, 'preview_converter'),
@@ -323,7 +323,7 @@ private function convertAttributes(\DOMElement $elementNode): array
323323
}
324324
foreach ($attributesNode->getElementsByTagName('complex_attribute') as $attributeNode) {
325325
$attributesData[] = [
326-
'var' => $this->getAttributeValue($attributeNode, 'name'),
326+
'var' => $this->extractVariableName($attributeNode),
327327
'reader' => $this->getAttributeValue($attributeNode, 'reader'),
328328
'converter' => $this->getAttributeValue($attributeNode, 'converter'),
329329
'preview_converter' => $this->getAttributeValue($attributeNode, 'preview_converter'),
@@ -455,4 +455,16 @@ private function getAttributeValue(\DOMElement $attributeNode, $attributeName)
455455
? $attributeNode->attributes->getNamedItem($attributeName)->nodeValue
456456
: null;
457457
}
458+
459+
/**
460+
* Extract variable name from property and attribute nodes
461+
*
462+
* @param \DOMElement $node
463+
* @return string
464+
*/
465+
private function extractVariableName(\DOMElement $node): string
466+
{
467+
return $this->getAttributeValue($node, 'storage_key')
468+
?: $this->getAttributeValue($node, 'name');
469+
}
458470
}

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ The following is an example of a content type configuration in `view/adminhtml/p
123123
<element name="link">
124124
<attributes>
125125
<complex_attribute name="link_url" reader="Magento_PageBuilder/js/property/link" persist="false"/>
126-
<attribute name="link_url" source="href" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-href" />
127-
<attribute name="link_url" source="target" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-target" />
128-
<attribute name="link_url" source="data-link-type" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-type" />
126+
<attribute name="virtual_link_href" storage_key="link_url" source="href" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-href"/>
127+
<attribute name="virtual_link_target" storage_key="link_url" source="target" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-target"/>
128+
<attribute name="virtual_link_type" storage_key="link_url" source="data-link-type" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-type"/>
129129
</attributes>
130130
</element>
131131
<element name="overlay">
@@ -137,7 +137,7 @@ The following is an example of a content type configuration in `view/adminhtml/p
137137
<attributes>
138138
<attribute name="overlay_color" source="data-overlay-color" persist="false" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-color"/>
139139
<attribute name="overlay_transparency" source="data-overlay-color" persist="false" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-transparency"/>
140-
<attribute name="overlay_transparency" source="data-overlay-color" virtual="true" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-color-transparency"/>
140+
<attribute name="virtual_overlay_transparency" storage_key="overlay_transparency" source="data-overlay-color" virtual="true" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-color-transparency"/>
141141
</attributes>
142142
</element>
143143
<element name="desktop_image">
@@ -316,16 +316,16 @@ Set the `default` attribute to "true" in an `appearance` node to set the default
316316
<element name="link">
317317
<attributes>
318318
<complex_attribute name="link_url" reader="Magento_PageBuilder/js/property/link" persist="false"/>
319-
<attribute name="link_url" source="href" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-href" />
320-
<attribute name="link_url" source="target" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-target" />
321-
<attribute name="link_url" source="data-link-type" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-type" />
319+
<attribute name="virtual_link_href" storage_key="link_url" source="href" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-href"/>
320+
<attribute name="virtual_link_target" storage_key="link_url" source="target" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-target"/>
321+
<attribute name="virtual_link_type" storage_key="link_url" source="data-link-type" virtual="true" converter="Magento_PageBuilder/js/converter/attribute/link-type"/>
322322
</attributes>
323323
</element>
324324
<element name="overlay">
325325
<attributes>
326326
<attribute name="overlay_color" source="data-overlay-color" persist="false" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-color"/>
327327
<attribute name="overlay_transparency" source="data-overlay-color" persist="false" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-transparency"/>
328-
<attribute name="overlay_transparency" source="data-overlay-color" virtual="true" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-color-transparency"/>
328+
<attribute name="virtual_overlay_transparency" storage_key="overlay_transparency" source="data-overlay-color" virtual="true" converter="Magento_PageBuilder/js/converter/banner/attribute/overlay-color-transparency"/>
329329
</attributes>
330330
</element>
331331
<element name="desktop_image">
@@ -370,7 +370,8 @@ Name attribute in the element tags gets converted to ```data-element``` attribut
370370

371371
| Attribute | Description |
372372
| ------------------- | ---------------------------------------------------------------------------------------------------------------------- |
373-
| `name` | The variable name for value in the data storage. Must be unique for the content type. |
373+
| `name` | Unique name used for configuration merging, and the default value for storage_key if none is provided. |
374+
| `storage_key` | Optional variable name for value in the data storage. If no value is provided, name will be used. |
374375
| `source` | The name of the property in the DOM. Must be in snake case. |
375376
| `converter` | Converts the value after reading or before saving to the DOM. |
376377
| `preview_converter` | Converts the value for the preview. Used for cases where the conversion logic is different between the two views. |
@@ -383,7 +384,7 @@ Name attribute in the element tags gets converted to ```data-element``` attribut
383384

384385
``` xml
385386
<style_properties>
386-
<complex_property name="margins_and_padding" reader="Magento_PageBuilder/js/property/margins" converter="Magento_PageBuilder/js/converter/style/margins"/>
387+
<complex_property name="margins" storage_key="margins_and_padding" reader="Magento_PageBuilder/js/property/margins" converter="Magento_PageBuilder/js/converter/style/margins"/>
387388
</style_properties>
388389
```
389390

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ To add configuration for a new content type, create a file under the following l
8989
<property name="border_color" source="border_color" converter="Magento_PageBuilder/js/converter/style/color"/>
9090
<property name="border_width" source="border_width" converter="Magento_PageBuilder/js/converter/style/border-width"/>
9191
<property name="border_radius" source="border_radius" converter="Magento_PageBuilder/js/converter/style/remove-px"/>
92-
<complex_property name="margins_and_padding" reader="Magento_PageBuilder/js/property/margins" converter="Magento_PageBuilder/js/converter/style/margins"/>
93-
<complex_property name="margins_and_padding" reader="Magento_PageBuilder/js/property/paddings" converter="Magento_PageBuilder/js/converter/style/paddings"/>
92+
<complex_property name="margins" storage_key="margins_and_padding" reader="Magento_PageBuilder/js/property/margins" converter="Magento_PageBuilder/js/converter/style/margins"/>
93+
<complex_property name="padding" storage_key="margins_and_padding" reader="Magento_PageBuilder/js/property/paddings" converter="Magento_PageBuilder/js/converter/style/paddings"/>
9494
</style_properties>
9595
<attributes>
9696
<attribute name="name" source="data-role"/>
@@ -294,8 +294,8 @@ Now, let's add content type that can contain other content types. Create configu
294294
<property name="border_color" source="border_color" converter="Magento_PageBuilder/js/converter/style/color"/>
295295
<property name="border_width" source="border_width" converter="Magento_PageBuilder/js/converter/style/border-width"/>
296296
<property name="border_radius" source="border_radius" converter="Magento_PageBuilder/js/converter/style/remove-px"/>
297-
<complex_property name="margins_and_padding" reader="Magento_PageBuilder/js/property/margins" converter="Magento_PageBuilder/js/converter/style/margins"/>
298-
<complex_property name="margins_and_padding" reader="Magento_PageBuilder/js/property/paddings" converter="Magento_PageBuilder/js/converter/style/paddings"/>
297+
<complex_property name="margins" storage_key="margins_and_padding" reader="Magento_PageBuilder/js/property/margins" converter="Magento_PageBuilder/js/converter/style/margins"/>
298+
<complex_property name="padding" storage_key="margins_and_padding" reader="Magento_PageBuilder/js/property/paddings" converter="Magento_PageBuilder/js/converter/style/paddings"/>
299299
</style_properties>
300300
<attributes>
301301
<attribute name="name" source="data-role"/>

app/code/Magento/PageBuilder/etc/content_type.xsd

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,28 @@
122122
</xs:complexType>
123123
<xs:complexType name="element">
124124
<xs:sequence>
125-
<xs:element type="style_properties" name="style_properties" minOccurs="0" maxOccurs="1"/>
126-
<xs:element type="attributes" name="attributes" minOccurs="0" maxOccurs="1"/>
125+
<xs:element type="style_properties" name="style_properties" minOccurs="0" maxOccurs="1">
126+
<xs:unique name="uniquePropertyName">
127+
<xs:annotation>
128+
<xs:documentation>
129+
Property and Complex Property name must be unique
130+
</xs:documentation>
131+
</xs:annotation>
132+
<xs:selector xpath="property|complex_property"/>
133+
<xs:field xpath="@name"/>
134+
</xs:unique>
135+
</xs:element>
136+
<xs:element type="attributes" name="attributes" minOccurs="0" maxOccurs="1">
137+
<xs:unique name="uniqueAttributeName">
138+
<xs:annotation>
139+
<xs:documentation>
140+
Attribute and Complex Attribute name must be unique
141+
</xs:documentation>
142+
</xs:annotation>
143+
<xs:selector xpath="attribute|complex_attribute"/>
144+
<xs:field xpath="@name"/>
145+
</xs:unique>
146+
</xs:element>
127147
<xs:element type="tag" name="tag" minOccurs="0" maxOccurs="1"/>
128148
<xs:element type="html" name="html" minOccurs="0" maxOccurs="1"/>
129149
<xs:element type="css" name="css" minOccurs="0" maxOccurs="1"/>
@@ -149,13 +169,15 @@
149169
<xs:attribute type="xs:string" name="preview_converter" use="optional"/>
150170
<xs:attribute type="xs:string" name="virtual" use="optional"/>
151171
<xs:attribute type="xs:string" name="persist" use="optional"/>
172+
<xs:attribute type="xs:string" name="storage_key" use="optional"/>
152173
</xs:complexType>
153174
<xs:complexType name="complex_property">
154175
<xs:attribute type="xs:string" name="name" use="required"/>
155176
<xs:attribute type="xs:string" name="reader" use="optional"/>
156177
<xs:attribute type="xs:string" name="converter" use="optional"/>
157178
<xs:attribute type="xs:string" name="preview_converter" use="optional"/>
158179
<xs:attribute type="xs:string" name="virtual" use="optional"/>
180+
<xs:attribute type="xs:string" name="storage_key" use="optional"/>
159181
</xs:complexType>
160182
<xs:complexType name="static_property">
161183
<xs:attribute type="xs:string" name="source" use="required"/>
@@ -175,6 +197,7 @@
175197
<xs:attribute type="xs:string" name="preview_converter" use="optional"/>
176198
<xs:attribute type="xs:string" name="virtual" use="optional"/>
177199
<xs:attribute type="xs:boolean" name="persist" use="optional"/>
200+
<xs:attribute type="xs:string" name="storage_key" use="optional"/>
178201
</xs:complexType>
179202
<xs:complexType name="complex_attribute">
180203
<xs:attribute type="xs:string" name="name" use="required"/>
@@ -183,6 +206,7 @@
183206
<xs:attribute type="xs:string" name="preview_converter" use="optional"/>
184207
<xs:attribute type="xs:string" name="virtual" use="optional"/>
185208
<xs:attribute type="xs:boolean" name="persist" use="optional"/>
209+
<xs:attribute type="xs:string" name="storage_key" use="optional"/>
186210
</xs:complexType>
187211
<xs:complexType name="static_attribute">
188212
<xs:attribute type="xs:string" name="source" use="required"/>

app/code/Magento/PageBuilder/etc/content_type_merged.xsd

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,28 @@
122122
</xs:complexType>
123123
<xs:complexType name="element">
124124
<xs:sequence>
125-
<xs:element type="style_properties" name="style_properties" minOccurs="0" maxOccurs="1"/>
126-
<xs:element type="attributes" name="attributes" minOccurs="0" maxOccurs="1"/>
125+
<xs:element type="style_properties" name="style_properties" minOccurs="0" maxOccurs="1">
126+
<xs:unique name="uniquePropertyName">
127+
<xs:annotation>
128+
<xs:documentation>
129+
Property and Complex Property name must be unique
130+
</xs:documentation>
131+
</xs:annotation>
132+
<xs:selector xpath="property|complex_property"/>
133+
<xs:field xpath="@name"/>
134+
</xs:unique>
135+
</xs:element>
136+
<xs:element type="attributes" name="attributes" minOccurs="0" maxOccurs="1">
137+
<xs:unique name="uniqueAttributeName">
138+
<xs:annotation>
139+
<xs:documentation>
140+
Attribute and Complex Attribute name must be unique
141+
</xs:documentation>
142+
</xs:annotation>
143+
<xs:selector xpath="attribute|complex_attribute"/>
144+
<xs:field xpath="@name"/>
145+
</xs:unique>
146+
</xs:element>
127147
<xs:element type="tag" name="tag" minOccurs="0" maxOccurs="1"/>
128148
<xs:element type="html" name="html" minOccurs="0" maxOccurs="1"/>
129149
<xs:element type="css" name="css" minOccurs="0" maxOccurs="1"/>
@@ -149,13 +169,15 @@
149169
<xs:attribute type="xs:string" name="preview_converter" use="optional"/>
150170
<xs:attribute type="xs:string" name="virtual" use="optional"/>
151171
<xs:attribute type="xs:string" name="persist" use="optional"/>
172+
<xs:attribute type="xs:string" name="storage_key" use="optional"/>
152173
</xs:complexType>
153174
<xs:complexType name="complex_property">
154175
<xs:attribute type="xs:string" name="name" use="required"/>
155176
<xs:attribute type="xs:string" name="reader" use="required"/>
156177
<xs:attribute type="xs:string" name="converter" use="optional"/>
157178
<xs:attribute type="xs:string" name="preview_converter" use="optional"/>
158179
<xs:attribute type="xs:string" name="virtual" use="optional"/>
180+
<xs:attribute type="xs:string" name="storage_key" use="optional"/>
159181
</xs:complexType>
160182
<xs:complexType name="static_property">
161183
<xs:attribute type="xs:string" name="source" use="required"/>
@@ -176,6 +198,7 @@
176198
<xs:attribute type="xs:string" name="preview_converter" use="optional"/>
177199
<xs:attribute type="xs:string" name="virtual" use="optional"/>
178200
<xs:attribute type="xs:boolean" name="persist" use="optional"/>
201+
<xs:attribute type="xs:string" name="storage_key" use="optional"/>
179202
</xs:complexType>
180203
<xs:complexType name="complex_attribute">
181204
<xs:attribute type="xs:string" name="name" use="required"/>
@@ -184,6 +207,7 @@
184207
<xs:attribute type="xs:string" name="preview_converter" use="optional"/>
185208
<xs:attribute type="xs:string" name="virtual" use="optional"/>
186209
<xs:attribute type="xs:boolean" name="persist" use="optional"/>
210+
<xs:attribute type="xs:string" name="storage_key" use="optional"/>
187211
</xs:complexType>
188212
<xs:complexType name="static_attribute">
189213
<xs:attribute type="xs:string" name="source" use="required"/>

0 commit comments

Comments
 (0)