Skip to content

Commit c74de06

Browse files
committed
PB-419: Resolve BiC change within content type toolbar
- Include compatibility functions to ensure extensions consuming previewData do not stop functioning
1 parent 612c402 commit c74de06

File tree

2 files changed

+79
-1
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+79
-1
lines changed

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

Lines changed: 42 additions & 0 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/ts/js/content-type/preview.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import "../binding/sortable";
1414
import "../binding/sortable-children";
1515
import ContentTypeCollection from "../content-type-collection";
1616
import ContentTypeCollectionInterface from "../content-type-collection.types";
17-
import ContentTypeConfigInterface from "../content-type-config.types";
17+
import ContentTypeConfigInterface, {ConfigFieldInterface} from "../content-type-config.types";
1818
import createContentType from "../content-type-factory";
1919
import ContentTypeMenu from "../content-type-menu";
2020
import Edit from "../content-type-menu/edit";
@@ -46,6 +46,13 @@ export default class Preview implements PreviewInterface {
4646
public isPlaceholderVisible: KnockoutObservable<boolean> = ko.observable(true);
4747
public isEmpty: KnockoutObservable<boolean> = ko.observable(true);
4848

49+
/**
50+
* Provide preview data as an object which can be queried
51+
*
52+
* @deprecated please use getOptionValue directly
53+
*/
54+
public previewData = {};
55+
4956
/**
5057
* Fields that should not be considered when evaluating whether an object has been configured.
5158
*
@@ -82,6 +89,7 @@ export default class Preview implements PreviewInterface {
8289
"empty-placeholder-background": this.isPlaceholderVisible,
8390
});
8491
this.bindEvents();
92+
this.populatePreviewData();
8593
}
8694

8795
/**
@@ -144,6 +152,15 @@ export default class Preview implements PreviewInterface {
144152
this.contentType.dataStore.set(key, value);
145153
}
146154

155+
/**
156+
* Retrieve the value for an option
157+
*
158+
* @param key
159+
*/
160+
public getOptionValue(key: string) {
161+
return this.contentType.dataStore.get(key);
162+
}
163+
147164
/**
148165
* Set state based on mouseover event for the preview
149166
*
@@ -581,4 +598,23 @@ export default class Preview implements PreviewInterface {
581598

582599
this.isPlaceholderVisible(paddingBottom + paddingTop + minHeight >= 130);
583600
}
601+
602+
/**
603+
* Populate the preview data with calls to the supported getOptionValue method
604+
*
605+
* @deprecated this function is only included to preserve backwards compatibility, use getOptionValue directly
606+
*/
607+
private populatePreviewData(): void {
608+
const response: {[key: string]: () => any} = {};
609+
if (this.config.fields) {
610+
_.each(this.config.fields, (fields) => {
611+
_.keys(fields).forEach((key: string) => {
612+
response[key] = () => {
613+
return this.getOptionValue(key);
614+
};
615+
});
616+
});
617+
}
618+
this.previewData = response;
619+
}
584620
}

0 commit comments

Comments
 (0)