Skip to content

Commit 48dae1c

Browse files
Merge branch 'develop' of github.com:magento/magento2-page-builder into PB-416-phpgtdom
2 parents 2b0627f + dc3d35b commit 48dae1c

File tree

5 files changed

+136
-8
lines changed

5 files changed

+136
-8
lines changed

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

Lines changed: 53 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: 51 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: {[key: string]: KnockoutObservable<any>} = {};
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,37 @@ 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+
if (this.config.fields) {
609+
_.each(this.config.fields, (fields) => {
610+
_.keys(fields).forEach((key: string) => {
611+
this.previewData[key] = ko.observable("");
612+
});
613+
});
614+
}
615+
616+
// Subscribe to this content types data in the store
617+
this.contentType.dataStore.subscribe(
618+
(data: DataObject) => {
619+
_.forEach(data, (value, key) => {
620+
const optionValue = this.getOptionValue(key);
621+
if (ko.isObservable(this.previewData[key])) {
622+
this.previewData[key](optionValue);
623+
} else {
624+
if (_.isArray(optionValue)) {
625+
this.previewData[key] = ko.observableArray(optionValue);
626+
} else {
627+
this.previewData[key] = ko.observable(optionValue);
628+
}
629+
}
630+
});
631+
},
632+
);
633+
}
584634
}

app/code/Magento/PageBuilderAnalytics/Model/ContentTypeUsageReportProvider.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,13 @@ public function getReport($name) : \IteratorIterator
101101
foreach ($batchQuery->fetchAll() as $row) {
102102
foreach ($contentTypes as $type) {
103103
// Count the amount of content types within the content
104-
$typeCounts[$type['name']] += substr_count(
105-
$row['content'],
106-
'data-content-type="' . $type['name'] . '"'
107-
);
104+
$rowContent = $row['content'] ?? '';
105+
if (strlen($rowContent) > 0) {
106+
$typeCounts[$type['name']] += substr_count(
107+
$rowContent,
108+
'data-content-type="' . $type['name'] . '"'
109+
);
110+
}
108111
}
109112
}
110113
}

dev/tests/integration/_files/Magento/TestModuleCmsPageBuilderAnalytics/etc/reports.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</using>
1717
</link-source>
1818
<filter glue="and">
19-
<condition attribute="identifier" operator="eq">page-builder-analytics-test-page</condition>
19+
<condition attribute="identifier" operator="like">page-builder-analytics-test-page%</condition>
2020
</filter>
2121
</source>
2222
</report>
@@ -30,8 +30,8 @@
3030
</using>
3131
</link-source>
3232
<filter glue="and">
33-
<condition attribute="identifier" operator="eq">page-builder-analytics-test-page</condition>
33+
<condition attribute="identifier" operator="like">page-builder-analytics-test-page%</condition>
3434
</filter>
3535
</source>
3636
</report>
37-
</config>
37+
</config>

dev/tests/integration/testsuite/Magento/CmsPageBuilderAnalytics/_files/pages.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,25 @@
390390
->setContent($content)
391391
->setPageLayout('cms-full-width')
392392
->save();
393+
394+
/** @var $emptyContentPage \Magento\Cms\Model\Page */
395+
$emptyContentPage = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Cms\Model\Page::class);
396+
$emptyContentPage->setTitle('Page Builder Analytics Test Page - Empty Content')
397+
->setIdentifier('page-builder-analytics-test-page-empty')
398+
->setStores([0, 1])
399+
->setIsActive(1)
400+
->setCreatedIn(1)
401+
->setContent('')
402+
->setPageLayout('cms-full-width')
403+
->save();
404+
405+
/** @var $nullContentPage \Magento\Cms\Model\Page */
406+
$nullContentPage = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Cms\Model\Page::class);
407+
$nullContentPage->setTitle('Page Builder Analytics Test Page - Null Content')
408+
->setIdentifier('page-builder-analytics-test-page-null')
409+
->setStores([0, 1])
410+
->setIsActive(1)
411+
->setCreatedIn(1)
412+
->setContent(null)
413+
->setPageLayout('cms-full-width')
414+
->save();

0 commit comments

Comments
 (0)