Skip to content

Commit 2272e53

Browse files
Merge remote-tracking branch 'origin/MC-523-content-type-configuration-nodes-to-attributes' into cms-team-2-sprint-11
2 parents e3127e8 + 1b27fcb commit 2272e53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+602
-614
lines changed

app/code/Magento/PageBuilder/Model/Config/ContentType/AdditionalData/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
}
3131

3232
/**
33-
* Convert and evaluate additional data from arguments nodes to array
33+
* Convert and evaluate additional data from item nodes to array
3434
*
3535
* @param array $additionalData
3636
* @return array

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ private function convertTypes(\DOMDocument $source): array
5555
/** @var \DOMNode $contentType */
5656
foreach ($contentTypes as $contentType) {
5757
$name = $contentType->attributes->getNamedItem('name')->nodeValue;
58+
/** @var \DOMElement $attributeValue */
59+
foreach ($contentType->attributes as $attributeName => $attributeValue) {
60+
$typesData[$name][$attributeName] = $attributeValue->nodeValue;
61+
}
5862
/** @var \DOMElement $childNode */
5963
foreach ($contentType->childNodes as $childNode) {
6064
if ($this->isConfigNode($childNode)) {
@@ -113,14 +117,6 @@ private function convertAppearanceData(\DOMElement $appearanceNode): array
113117
$appearanceData,
114118
$this->convertAppearanceProperties($appearanceNode)
115119
);
116-
$previewTemplateNode = $appearanceNode->getElementsByTagName('preview_template')->item(0);
117-
if ($previewTemplateNode) {
118-
$appearanceData['preview_template'] = $previewTemplateNode->nodeValue;
119-
}
120-
$renderTemplateNode = $appearanceNode->getElementsByTagName('render_template')->item(0);
121-
if ($renderTemplateNode) {
122-
$appearanceData['render_template'] = $renderTemplateNode->nodeValue;
123-
}
124120
$readerNode = $appearanceNode->getElementsByTagName('reader')->item(0);
125121
if ($readerNode && $readerNode->nodeValue) {
126122
$appearanceData['readers'] = [$readerNode->nodeValue];
@@ -131,6 +127,9 @@ private function convertAppearanceData(\DOMElement $appearanceNode): array
131127
if ($dataMappingNode) {
132128
$appearanceData['data_mapping'] = $this->convertDataMapping($dataMappingNode);
133129
}
130+
$appearanceData['preview_template'] = $this->getAttributeValue($appearanceNode, 'preview_template');
131+
$appearanceData['render_template'] = $this->getAttributeValue($appearanceNode, 'render_template');
132+
$appearanceData['reader'] = $this->getAttributeValue($appearanceNode, 'reader');
134133
$appearanceData['default'] = $this->getAttributeValue($appearanceNode, 'default');
135134
$formNode = $appearanceNode->getElementsByTagName('form')->item(0);
136135
if ($formNode && $formNode->nodeValue) {
@@ -232,22 +231,23 @@ private function convertDataMapping(\DOMElement $childNode): array
232231
private function convertAdditionalData(\DOMElement $elementNode): array
233232
{
234233
$additionalData = [];
235-
$xmlArgumentsNodes = $elementNode->getElementsByTagName('arguments');
234+
$xmlItemNodes = $elementNode->childNodes;
236235

237-
if (!$xmlArgumentsNodes->length) {
236+
if (!$xmlItemNodes->length) {
238237
return $additionalData;
239238
}
240239

241-
/** @var $xmlArgumentsNode \DOMElement */
242-
foreach ($xmlArgumentsNodes as $xmlArgumentsNode) {
243-
$parsedArgumentsData = $this->parser->parse($xmlArgumentsNode);
244-
$argumentName = $xmlArgumentsNode->attributes->getNamedItem('name')->nodeValue;
240+
/** @var $xmlItemNode \DOMElement */
241+
foreach ($xmlItemNodes as $xmlItemNode) {
242+
if ($xmlItemNode->nodeType == XML_ELEMENT_NODE && $xmlItemNode->nodeName === 'item') {
243+
$parsedItemData = $this->parser->parse($xmlItemNode);
244+
$itemName = $xmlItemNode->attributes->getNamedItem('name')->nodeValue;
245245

246-
if (!isset($additionalData[$argumentName])) {
247-
$additionalData[$argumentName] = [];
246+
if (!isset($additionalData[$itemName])) {
247+
$additionalData[$itemName] = [];
248+
}
249+
$additionalData[$itemName] += $parsedItemData;
248250
}
249-
250-
$additionalData[$argumentName] += $parsedArgumentsData;
251251
}
252252

253253
return $additionalData;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Reader extends \Magento\Framework\Config\Reader\Filesystem
2929
=> 'name',
3030
self::TYPE_PATH . '/appearances/appearance/data_mapping/elements/element/style_properties/static_property'
3131
=> 'source',
32-
self::TYPE_PATH . '/additional_data/arguments' => 'name',
32+
self::TYPE_PATH . '/additional_data/item' => 'name',
3333
self::TYPE_PATH . '/appearances/appearance/data_mapping/elements/element/attributes/attribute' => 'name',
3434
self::TYPE_PATH . '/appearances/appearance/data_mapping/elements/element/attributes/complex_attribute'
3535
=> 'name',

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,10 @@ private function convertGroups(\DOMDocument $source): array
3939
foreach ($groups->item(0)->childNodes as $group) {
4040
if ($group->nodeType == XML_ELEMENT_NODE && $group->tagName == 'group') {
4141
$name = $group->attributes->getNamedItem('name')->nodeValue;
42-
/** @var \DOMElement $childNode */
43-
foreach ($group->childNodes as $childNode) {
44-
if ($this->isConfigNode($childNode)) {
45-
$groupsData[$name][$childNode->nodeName] = $childNode->nodeValue;
46-
}
42+
/** @var \DOMElement $attributeValue */
43+
foreach ($group->attributes as $attributeName => $attributeValue) {
44+
$groupsData[$name][$attributeName] = $attributeValue->nodeValue;
4745
}
48-
$groupsData[$name]['sortOrder'] = $group->hasAttribute('sortOrder')
49-
? $group->attributes->getNamedItem('sortOrder')->nodeValue
50-
: null;
5146
}
5247
}
5348
uasort($groupsData, function ($firstElement, $secondElement) {
@@ -56,18 +51,4 @@ private function convertGroups(\DOMDocument $source): array
5651

5752
return $groupsData;
5853
}
59-
60-
/**
61-
* Check if node is configuration node
62-
*
63-
* @param \DOMNode $node
64-
* @return bool
65-
*/
66-
private function isConfigNode(\DOMNode $node): bool
67-
{
68-
return $node->nodeType === XML_ELEMENT_NODE
69-
|| ($node->nodeType === XML_CDATA_SECTION_NODE
70-
|| $node->nodeType === XML_TEXT_NODE
71-
&& trim($node->nodeValue) !== '');
72-
}
7354
}

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

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,43 @@ The following is an example of a group configuration in `view/adminhtml/pagebuil
5454
``` xml
5555
<!-- Definition of main menu, used for grouping content types -->
5656
<groups>
57-
<group name="media" translate="label" sortOrder="10">
58-
<label>Media</label>
59-
</group>
57+
<group name="media" translate="label" sortOrder="10" label="Media"/>
6058
</groups>
6159
```
6260
### Configuration reference
6361

6462
| Element | Description |
6563
| ------------------- | ------------------------------------------------------------------------ |
6664
| `group` | Describes the group name, translated field, and sort order in the menu. |
67-
| `label` | Label displayed on the menu. |
6865

66+
| Attribute | Description |
67+
| ------------------- | ------------------------------------------------------------------------ |
68+
| `label` | Label displayed on the menu. |
6969

7070
The following is an example of a content type configuration in `view/adminhtml/pagebuilder/content_type/banner.xml`:
7171

7272
``` xml
7373
<content_types>
7474
<!-- Content type declaration -->
75-
<type name="banner" translate="label" sortOrder="1">
76-
<label>Banner</label>
77-
<icon>icon-pagebuilder-image</icon>
78-
<component>Magento_PageBuilder/js/content-type</component>
79-
<preview_component>Magento_PageBuilder/js/content-type/banner/preview</preview_component>
80-
<content_component>Magento_PageBuilder/js/content-type/content</content_component>
81-
<form>pagebuilder_banner_form</form>
82-
<group>media</group>
75+
<type name="banner"
76+
label="Banner"
77+
component="Magento_PageBuilder/js/content-type"
78+
preview_component="Magento_PageBuilder/js/content-type/banner/preview"
79+
form="pagebuilder_banner_form"
80+
group="media"
81+
icon="icon-pagebuilder-image"
82+
sortOrder="1"
83+
translate="label">
8384
<allowed_parents>
8485
<parent name="row"/>
8586
<parent name="column"/>
8687
</allowed_parents>
8788
<appearances>
88-
<appearance name="poster" default="true">
89+
<appearance default="true"
90+
name="poster"
91+
preview_template="Magento_PageBuilder/content-type/banner/poster/preview"
92+
render_template="Magento_PageBuilder/content-type/banner/poster/master"
93+
reader="Magento_PageBuilder/js/master-format/read/configurable">
8994
<data_mapping>
9095
<elements>
9196
<element name="main" path=".">
@@ -171,17 +176,23 @@ The following is an example of a content type configuration in `view/adminhtml/p
171176
</converter>
172177
</converters>
173178
</data_mapping>
174-
<preview_template>Magento_PageBuilder/content-type/banner/poster/preview</preview_template>
175-
<render_template>Magento_PageBuilder/content-type/banner/poster/master</render_template>
176-
<reader>Magento_PageBuilder/js/component/format/read/configurable</reader>
177179
</appearance>
178-
<appearance name="collage-left">
180+
<appearance name="collage-left"
181+
preview_template="Magento_PageBuilder/content-type/banner/collage-left/preview"
182+
render_template="Magento_PageBuilder/content-type/banner/collage-left/master"
183+
reader="Magento_PageBuilder/js/master-format/read/configurable">
179184
<!-- Collage left appearance configuration -->
180185
</appearance>
181-
<appearance name="collage-centered">
186+
<appearance name="collage-centered"
187+
preview_template="Magento_PageBuilder/content-type/banner/collage-centered/preview"
188+
render_template="Magento_PageBuilder/content-type/banner/collage-centered/master"
189+
reader="Magento_PageBuilder/js/master-format/read/configurable">
182190
<!-- Collage centered appearance configuration -->
183191
</appearance>
184-
<appearance name="collage-right">
192+
<appearance name="collage-right"
193+
preview_template="Magento_PageBuilder/content-type/banner/collage-right/preview"
194+
render_template="Magento_PageBuilder/content-type/banner/collage-right/master"
195+
reader="Magento_PageBuilder/js/master-format/read/configurable">
185196
<!-- Collage right appearance configuration -->
186197
</appearance>
187198
</appearances>
@@ -193,17 +204,20 @@ The following is an example of a content type configuration in `view/adminhtml/p
193204
| Element | Description |
194205
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
195206
| `type` | Describes the content type name, translated field, and sort order in the menu group. Each type should have its own configuration file. |
207+
| `allowed_parents` | List of parent content types that can accept this type as a child. |
208+
| `appearances` | Appearance configuration. |
209+
| `is_visible` | Determines menu visibility for the component. System components should not be visible in the menu. Default value is true. |
210+
| `additional_data` | Allows to specify additional data for component, see [custom configuration for content type](custom-configuration.md) for more information. |
211+
212+
| Attribute | Description |
213+
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
196214
| `label` | Label displayed on the menu and stage. |
197215
| `icon` | Icon displayed on the menu. |
198216
| `component` | View model responsible for rendering the preview and master format. |
199217
| `preview_component` | Helper component that contains preview specific logic. Helper component is optional. |
200-
| `content_component` | Contains master format rendering logic that is generic for all appearances. Content component is optional. |
218+
| `master_component` | Contains master format rendering logic that is generic for all appearances. Content component is optional. |
201219
| `form` | UI component form used for editing the content type |
202220
| `group` | Existing menu group that contains this content type. |
203-
| `allowed_parents` | List of parent content types that can accept this type as a child. |
204-
| `appearances` | Appearance configuration. |
205-
| `is_visible` | Determines menu visibility for the component. System components should not be visible in the menu. Default value is true. |
206-
| `additional_data` | Allows to specify additional data for component, see [custom configuration for content type](custom-configuration.md) for more information. |
207221

208222

209223
### `form` configuration reference
@@ -237,6 +251,9 @@ It controls the templates, how data is read from the master format, and how to a
237251
| ------------------- | -------------------------------------------------------------------------------------- |
238252
| `appearance` | The name of the appearance. Every content type requires one default appearance. |
239253
| `data_mapping` | Specifies how data is read from, saved to, and converted to and from the master format |
254+
255+
| Attribute | Description |
256+
| ------------------- | -------------------------------------------------------------------------------------- |
240257
| `preview_template` | Template used to display the element in the preview |
241258
| `render_template` | Template used to render the content type to the master format |
242259
| `reader` | Reads data for the content type from the master format |
@@ -246,11 +263,12 @@ It reads data based on the configuration specified in `data_mapping`.
246263

247264
**Example:**
248265
``` xml
249-
<appearance name="poster" default="true">
266+
<appearance default="true"
267+
name="poster"
268+
preview_template="Magento_PageBuilder/content-type/banner/poster/preview"
269+
render_template="Magento_PageBuilder/content-type/banner/poster/master"
270+
reader="Magento_PageBuilder/js/master-format/read/configurable">
250271
<data_mapping/>
251-
<preview_template>Magento_PageBuilder/content-type/banner/poster/preview</preview_template>
252-
<render_template>Magento_PageBuilder/content-type/banner/poster/master</render_template>
253-
<reader>Magento_PageBuilder/js/component/format/read/configurable</reader>
254272
</appearance>
255273
```
256274

app/code/Magento/PageBuilder/docs/custom-configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Use `additional_data` in your `Vendor/ModuleName/view/adminhtml/pagebuilder/cont
6464

6565
``` xml
6666
<additional_data>
67-
<arguments name="uploaderConfig" xsi:type="array">
67+
<item name="uploaderConfig" xsi:type="array">
6868
<item name="maxFileSize" xsi:type="object">Magento\PageBuilder\Model\Config\ContentType\AdditionalData\Provider\Uploader\MaxFileSize</item>
6969
<item name="allowedExtensions" xsi:type="string">jpg jpeg gif png</item>
7070
<item name="component" xsi:type="string">Magento_PageBuilder/js/form/element/image-uploader</item>
@@ -85,7 +85,7 @@ Use `additional_data` in your `Vendor/ModuleName/view/adminhtml/pagebuilder/cont
8585
<item name="validation" xsi:type="array">
8686
<item name="required-entry" xsi:type="boolean">true</item>
8787
</item>
88-
</arguments>
88+
</item>
8989
</additional_data>
9090
```
9191

0 commit comments

Comments
 (0)