Skip to content

Commit b8cd983

Browse files
committed
MC-5232: Prefix field names with section name to avoid field name collision
- Update documentation
1 parent 29089d0 commit b8cd983

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

docs/configurations/content-type-configuration.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ Set the `default` attribute to "true" in an `appearance` node to set the default
315315

316316
The name attribute in the element tags gets converted to a `data-element` attribute in the master format in order for readers to access the desired element.
317317

318-
### Attributes for `property` and `attribute`
318+
### Attributes for `style`, `property` and `attribute`
319319

320320
| Attribute | Description |
321321
| --------------------- | ----------------------------------------------------------------------------------------------------------------------|
322322
| `name` | Unique name used for configuration merging, and the default value for storage_key if none is provided. |
323-
| `storage_key` | Optional variable name for value in the data storage. If no value is provided, name will be used. |
323+
| `storage_key` | Optional variable name for value in the data storage. If no value is provided, name will be used. This is the form fields data scope which is typically the name unless a `dataScope` is provided on the field. Supports the dot notation for `dataScope` (such as `layout.min_height`) |
324324
| `source` | The name of the property or attribute in the DOM. Must be in snake case. |
325325
| `converter` | Converts the value after reading or before saving to the DOM. |
326326
| `preview_converter` | Converts the value for the preview. Used for cases where the conversion logic is different between the two views. |
@@ -398,12 +398,14 @@ The `fromDom` method is called after data is read from the master format.
398398

399399
The `toDom` method is called before observables are updated in the cycle rendering preview or master format.
400400

401+
When accessing data provided into the above functions **you should** utilise the `get` and `set` utility functions from `Magento_PageBuilder/js/utils/object` to ensure any data mapping entries which traverse deeper into the data set with the dot notation can correctly retrieve and set their data.
402+
401403
**Example:**
402404

403405
The following is a converter that determines the output for an overlay background color:
404406

405407
``` js
406-
define(["Magento_PageBuilder/js/utils/color-converter", "Magento_PageBuilder/js/utils/number-converter"], function (colorConverter, numberConverter) {
408+
define(["Magento_PageBuilder/js/utils/color-converter", "Magento_PageBuilder/js/utils/number-converter", "Magento_PageBuilder/js/utils/object"], function (colorConverter, numberConverter, objectUtil) {
407409
var OverlayBackgroundColor = function () {};
408410

409411
/**
@@ -444,6 +446,8 @@ The `fromDom` method is called after data is read for all elements and converted
444446

445447
The `toDom` method is called before data is converted by element converters to update observables.
446448

449+
When accessing data provided into the above functions **you should** utilise the `get` and `set` utility functions from `Magento_PageBuilder/js/utils/object` to ensure any data mapping entries which traverse deeper into the data set with the dot notation can correctly retrieve and set their data.
450+
447451
**Example:** Mass converter that defaults mobile image value to desktop image value if not configured
448452
``` xml
449453
<converters>
@@ -457,7 +461,7 @@ The `toDom` method is called before data is converted by element converters to u
457461
```
458462

459463
``` js
460-
define([], function () {
464+
define(["Magento_PageBuilder/js/utils/object"], function (objectUtil) {
461465
var EmptyMobileImage = function () {};
462466

463467
/**
@@ -468,14 +472,14 @@ define([], function () {
468472
* @returns {object}
469473
*/
470474
EmptyMobileImage.prototype.fromDom = function fromDom(data, config) {
471-
var desktopImage = data[config.desktop_image_variable];
472-
var mobileImage = data[config.mobile_image_variable];
473-
474-
if (mobileImage && desktopImage && mobileImage[0] !== undefined && desktopImage[0] !== undefined && mobileImage[0].url === desktopImage[0].url) {
475-
delete data[config.mobile_image_variable];
476-
}
477-
478-
return data;
475+
var desktopImage = objectUtil.get(data, config.desktop_image_variable);
476+
var mobileImage = objectUtil.get(data, config.mobile_image_variable);
477+
478+
if (mobileImage && desktopImage && mobileImage[0] !== undefined && desktopImage[0] !== undefined && mobileImage[0].url === desktopImage[0].url) {
479+
delete data[config.mobile_image_variable];
480+
}
481+
482+
return data;
479483
};
480484

481485
/**
@@ -486,11 +490,13 @@ define([], function () {
486490
* @returns {object}
487491
*/
488492
EmptyMobileImage.prototype.toDom = function toDom(data, config) {
489-
if (data[config.mobile_image_variable] === undefined || data[config.mobile_image_variable][0] === undefined) {
490-
data[config.mobile_image_variable] = data[config.desktop_image_variable];
491-
}
492-
493-
return data;
493+
var mobileImage = objectUtil.get(data, config.mobile_image_variable);
494+
495+
if (mobileImage === undefined || mobileImage[0] === undefined) {
496+
objectUtil.set(data, config.mobile_image_variable, objectUtil.get(data, config.desktop_image_variable));
497+
}
498+
499+
return data;
494500
};
495501

496502
return EmptyMobileImage;

0 commit comments

Comments
 (0)