Skip to content

Commit 7d4230c

Browse files
committed
MC-5232: Prefix field names with section name to avoid field name collision
- Revert some code to prefix all field names - Add object-path for better object value getting and setting - Introduce support for dataScope
1 parent cf94d74 commit 7d4230c

File tree

19 files changed

+584
-244
lines changed

19 files changed

+584
-244
lines changed

app/code/Magento/PageBuilder/Model/Stage/Config/UiComponentConfig.php

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,53 +46,69 @@ public function getFields($componentName) : array
4646

4747
$fields = $this->iterateComponents(
4848
$componentConfig,
49-
function ($item, $fieldset, $key) {
49+
function ($item, $key) {
5050
// Determine if this item has a formElement key
5151
if (isset($item[Converter::DATA_ARGUMENTS_KEY]['data']['config']['formElement'])) {
5252
$elementConfig = $item[Converter::DATA_ARGUMENTS_KEY]['data']['config'];
53-
return [
54-
$fieldset => [
55-
$key => [
56-
'default' => (isset($elementConfig['default']) ? $elementConfig['default'] : '')
57-
]
58-
]
59-
];
53+
// If the field has a dataScope use that for the key instead of the name
54+
if (isset($elementConfig['dataScope'])) {
55+
$key = $elementConfig['dataScope'];
56+
}
57+
$field = [];
58+
// Generate our nested field array with defaults supporting dot notation within the key
59+
$this->generateFieldArray(
60+
$field,
61+
$key . ".default",
62+
(isset($elementConfig['default']) ? $elementConfig['default'] : '')
63+
);
64+
return $field;
6065
}
6166
}
6267
);
6368

6469
return $fields;
6570
}
6671

72+
/**
73+
* Recursively generate our field array, allowing for dot notation within the key
74+
*
75+
* @param $array
76+
* @param $path
77+
* @param $value
78+
*/
79+
private function generateFieldArray(array &$array, $path, $value) {
80+
$keys = explode(".", $path);
81+
82+
foreach ($keys as $key) {
83+
$array = &$array[$key];
84+
}
85+
86+
$array = $value;
87+
}
88+
6789
/**
6890
* Iterate over components within the configuration and run a defined callback function
6991
*
7092
* @param array $config
7193
* @param \Closure $callback
72-
* @param bool $fieldset
7394
* @param bool $key
7495
*
7596
* @return array
7697
*/
77-
private function iterateComponents($config, $callback, $fieldset = false, $key = false) : array
98+
private function iterateComponents($config, $callback, $key = false) : array
7899
{
79-
$values = $callback($config, $fieldset, $key) ?: [];
100+
$values = $callback($config, $key) ?: [];
80101
if (isset($config[Converter::DATA_COMPONENTS_KEY])
81102
&& !empty($config[Converter::DATA_COMPONENTS_KEY])
82103
&& (!isset($config[Converter::DATA_ARGUMENTS_KEY]['data']['config']['componentType'])
83104
|| isset($config[Converter::DATA_ARGUMENTS_KEY]['data']['config']['componentType'])
84105
&& $config[Converter::DATA_ARGUMENTS_KEY]['data']['config']['componentType'] !== 'dynamicRows'
85106
)
86107
) {
87-
// Retrieve the fieldset name from the configuration
88-
if ($config[Converter::DATA_ATTRIBUTES_KEY]['class'] === \Magento\Ui\Component\Form\Fieldset::class) {
89-
$fieldset = $config[Converter::DATA_ATTRIBUTES_KEY]['name'];
90-
}
91-
92108
foreach ($config[Converter::DATA_COMPONENTS_KEY] as $key => $child) {
93109
$values = array_merge_recursive(
94110
$values,
95-
$this->iterateComponents($child, $callback, $fieldset, $key) ?: []
111+
$this->iterateComponents($child, $callback, $key) ?: []
96112
);
97113
}
98114
}

app/code/Magento/PageBuilder/view/adminhtml/pagebuilder/content_type/row.xml

Lines changed: 84 additions & 84 deletions
Large diffs are not rendered by default.

app/code/Magento/PageBuilder/view/adminhtml/requirejs-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ var config = {
1010
'pagebuilder/ko-dropzone': 'Magento_PageBuilder/js/resource/dropzone/knockout-dropzone',
1111

1212
/* Utilities */
13-
'google-map': 'Magento_PageBuilder/js/utils/map'
13+
'google-map': 'Magento_PageBuilder/js/utils/map',
14+
'object-path': 'Magento_PageBuilder/js/resource/object-path',
1415
}
1516
},
1617
shim: {

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

Lines changed: 18 additions & 10 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/content-type-menu/edit.js

Lines changed: 1 addition & 1 deletion
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/data-store.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)