Skip to content

Commit 4c9419f

Browse files
Merge branch 'develop' into 1.4.0-release-sync
2 parents 2c8c1d1 + f7dfa4c commit 4c9419f

File tree

6 files changed

+109
-7
lines changed

6 files changed

+109
-7
lines changed

app/code/Magento/PageBuilder/Model/WidgetInitializerConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function getConfig(): array
4747
{
4848
$resultConfig = [];
4949
foreach ($this->config as $contentTypeName => $config) {
50-
$selector = sprintf('[data-content-type="%s"]', $contentTypeName);
5150
foreach ($config as $item) {
51+
$selector = sprintf('[data-content-type="%s"]', $contentTypeName);
5252
if (!isset($item['component'])) {
5353
continue;
5454
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\Test\Unit\Model;
9+
10+
use Magento\PageBuilder\Model\WidgetInitializerConfig;
11+
use PHPUnit\Framework\TestCase;
12+
13+
/**
14+
* Test for WidgetInitializerConfig
15+
*/
16+
class WidgetInitializerConfigTest extends TestCase
17+
{
18+
/**
19+
* Test different config variation.
20+
*
21+
* @dataProvider configProvider
22+
* @param array $config
23+
* @param array $expectedConfig
24+
*/
25+
public function testGetConfig(array $config, array $expectedConfig): void
26+
{
27+
$model = new WidgetInitializerConfig(
28+
$config
29+
);
30+
31+
$actualConfig = $model->getConfig();
32+
$this->assertEquals($expectedConfig, $actualConfig);
33+
}
34+
35+
/**
36+
* @return array
37+
*/
38+
public function configProvider(): array
39+
{
40+
return [
41+
[
42+
[
43+
'products' => [
44+
'default' => [
45+
'component' => 'test',
46+
'appearance' => 'default',
47+
'config' => [
48+
'a' => true
49+
]
50+
]
51+
]
52+
],
53+
[
54+
'[data-content-type="products"][data-appearance="default"]' => [
55+
'test' => [
56+
'a' => true
57+
]
58+
]
59+
]
60+
],
61+
[
62+
[
63+
'products' => [
64+
'default' => [
65+
'component' => 'test-component',
66+
'appearance' => 'default',
67+
'config' => [
68+
'a' => true
69+
]
70+
],
71+
'another' => [
72+
'component' => 'another-test-component',
73+
'appearance' => 'not_default',
74+
'config' => [
75+
'b' => false
76+
]
77+
]
78+
]
79+
],
80+
[
81+
'[data-content-type="products"][data-appearance="default"]' => [
82+
'test-component' => [
83+
'a' => true
84+
]
85+
],
86+
'[data-content-type="products"][data-appearance="not_default"]' => [
87+
'another-test-component' => [
88+
'b' => false
89+
]
90+
]
91+
]
92+
]
93+
];
94+
}
95+
}

app/code/Magento/PageBuilder/view/adminhtml/web/js/master-format/render.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.

app/code/Magento/PageBuilder/view/adminhtml/web/js/master-format/render/frame.js

Lines changed: 6 additions & 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/ts/js/master-format/render.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ export default class MasterFormatRenderer {
8080
this.channel = new MessageChannel();
8181
const frame = this.getRenderFrame();
8282
window.addEventListener("message", (event) => {
83-
if (!this.ready && event.data === "PB_RENDER_READY") {
83+
if (!this.ready && event.data.name === "PB_RENDER_READY" && this.stageId === event.data.stageId) {
8484
frame.contentWindow.postMessage("PB_RENDER_PORT", "*", [this.channel.port2]);
8585
this.ready = true;
8686
this.readyDeferred.resolve();
8787
}
8888
});
89-
frame.src = Config.getConfig("render_url");
89+
frame.src = Config.getConfig("render_url") + "?stageId=" + this.stageId;
9090
}
9191

9292
/**

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/master-format/render/frame.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const debounceRender = _.debounce((message: {stageId: string, tree: TreeItem}, r
4141
* Listen for requests from the parent window for a render
4242
*/
4343
export default function listen(config: ConfigInterface) {
44+
const stageId = window.location.href.split("?")[1].split("=")[1];
45+
4446
Config.setConfig(config);
4547
Config.setMode("Master");
4648

@@ -74,7 +76,7 @@ export default function listen(config: ConfigInterface) {
7476
);
7577

7678
// Inform the parent iframe that we're ready to receive the port
77-
window.parent.postMessage("PB_RENDER_READY", "*");
79+
window.parent.postMessage({name: "PB_RENDER_READY", stageId}, "*");
7880
}
7981

8082
/**

0 commit comments

Comments
 (0)