Skip to content

Commit 6ec8f80

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into MQE-1073
2 parents c91c0d1 + 4711583 commit 6ec8f80

File tree

301 files changed

+9571
-5740
lines changed

Some content is hidden

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

301 files changed

+9571
-5740
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: 20 additions & 19 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) {
@@ -204,7 +203,8 @@ private function convertDataMapping(\DOMElement $childNode): array
204203
$elementData = [];
205204
foreach ($childNode->getElementsByTagName('element') as $elementNode) {
206205
$elementName = $elementNode->attributes->getNamedItem('name')->nodeValue;
207-
$elementPath = $elementNode->attributes->getNamedItem('path')->nodeValue;
206+
$elementPath = ($elementNode->attributes->getNamedItem('path')
207+
? $elementNode->attributes->getNamedItem('path')->nodeValue : '');
208208
$elementData[$elementName] = [
209209
'path' => $elementPath,
210210
'style' => $this->convertProperties($elementNode),
@@ -232,22 +232,23 @@ private function convertDataMapping(\DOMElement $childNode): array
232232
private function convertAdditionalData(\DOMElement $elementNode): array
233233
{
234234
$additionalData = [];
235-
$xmlArgumentsNodes = $elementNode->getElementsByTagName('arguments');
235+
$xmlItemNodes = $elementNode->childNodes;
236236

237-
if (!$xmlArgumentsNodes->length) {
237+
if (!$xmlItemNodes->length) {
238238
return $additionalData;
239239
}
240240

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

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

253254
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/Model/Stage/Config.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Config
1515
const DEFAULT_PREVIEW_COMPONENT = 'Magento_PageBuilder/js/content-type/preview';
1616
const DEFAULT_MASTER_COMPONENT = 'Magento_PageBuilder/js/content-type/master';
1717

18+
const XML_PATH_COLUMN_GRID_DEFAULT = 'cms/pagebuilder/column_grid_default';
19+
const XML_PATH_COLUMN_GRID_MAX = 'cms/pagebuilder/column_grid_max';
20+
1821
/**
1922
* @var \Magento\PageBuilder\Model\Config\ConfigInterface
2023
*/
@@ -46,13 +49,18 @@ class Config
4649
private $additionalDataParser;
4750

4851
/**
49-
* Constructor
50-
*
52+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
53+
*/
54+
private $scopeConfig;
55+
56+
/**
57+
* Config constructor.
5158
* @param \Magento\PageBuilder\Model\Config\ConfigInterface $config
5259
* @param Config\UiComponentConfig $uiComponentConfig
53-
* @param \Magento\Framework\UrlInterface $urlBuilder
60+
* @param UrlInterface $urlBuilder
5461
* @param \Magento\Framework\Url $frontendUrlBuilder
5562
* @param \Magento\PageBuilder\Model\Config\ContentType\AdditionalData\Parser $additionalDataParser
63+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
5664
* @param array $data
5765
*/
5866
public function __construct(
@@ -61,13 +69,15 @@ public function __construct(
6169
\Magento\Framework\UrlInterface $urlBuilder,
6270
\Magento\Framework\Url $frontendUrlBuilder,
6371
\Magento\PageBuilder\Model\Config\ContentType\AdditionalData\Parser $additionalDataParser,
72+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
6473
array $data = []
6574
) {
6675
$this->config = $config;
6776
$this->uiComponentConfig = $uiComponentConfig;
6877
$this->urlBuilder = $urlBuilder;
6978
$this->frontendUrlBuilder = $frontendUrlBuilder;
7079
$this->additionalDataParser = $additionalDataParser;
80+
$this->scopeConfig = $scopeConfig;
7181
$this->data = $data;
7282
}
7383

@@ -83,7 +93,9 @@ public function getConfig()
8393
'content_types' => $this->getContentTypes(),
8494
'stage_config' => $this->data,
8595
'media_url' => $this->urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]),
86-
'preview_url' => $this->frontendUrlBuilder->getUrl('pagebuilder/contenttype/preview')
96+
'preview_url' => $this->frontendUrlBuilder->getUrl('pagebuilder/contenttype/preview'),
97+
'column_grid_default' => $this->scopeConfig->getValue(self::XML_PATH_COLUMN_GRID_DEFAULT),
98+
'column_grid_max' => $this->scopeConfig->getValue(self::XML_PATH_COLUMN_GRID_MAX),
8799
];
88100
}
89101

app/code/Magento/PageBuilder/Setup/DataConverter/ChildrenRenderer/Row.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ private function getColumnWidth($column)
102102
return 0;
103103
}
104104

105-
$width = $column['formData']['width'];
106-
if (isset(Column::COLUMN_WIDTH_MAPPING[$width])) {
107-
$width = Column::COLUMN_WIDTH_MAPPING[$width];
108-
}
109-
110-
return $width;
105+
return $column['formData']['width'];
111106
}
112107
}

app/code/Magento/PageBuilder/Setup/DataConverter/Renderer/Column.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
*/
1414
class Column implements RendererInterface
1515
{
16-
// Defined column mapping to supported widths
16+
// We have to map as we are unable to calculate the new column width effectively for all sizes
1717
const COLUMN_WIDTH_MAPPING = [
18-
'0.250' => '0.167',
19-
'0.750' => '0.833'
18+
'0.167' => '16.6667',
19+
'0.250' => '25',
20+
'0.333' => '33.3333',
21+
'0.500' => '50',
22+
'0.666' => '66.6666',
23+
'0.750' => '75',
24+
'0.825' => '82.5000',
25+
'1.000' => '100',
2026
];
2127

2228
/**
@@ -74,13 +80,10 @@ public function render(array $itemData, array $additionalData = [])
7480
*/
7581
private function calculateColumnWidth($oldWidth)
7682
{
77-
// Map column sizes to suitable sizes for columns we don't yet support
78-
if (isset(self::COLUMN_WIDTH_MAPPING[$oldWidth])) {
79-
$oldWidth = self::COLUMN_WIDTH_MAPPING[$oldWidth];
83+
if (!isset(self::COLUMN_WIDTH_MAPPING[number_format($oldWidth, 3)])) {
84+
throw new \InvalidArgumentException('Width ' . $oldWidth .' has no valid mapping.');
8085
}
8186

82-
// Resolve issues with old system storing non exact percentages (e.g. 0.167 != 16.6667%)
83-
$percentage = 100 / round(100 / ($oldWidth * 100), 1);
84-
return floatval(number_format($percentage, 4, '.', '')) . '%';
87+
return self::COLUMN_WIDTH_MAPPING[number_format($oldWidth, 3)] . '%';
8588
}
8689
}

0 commit comments

Comments
 (0)