Skip to content

Commit 70634ff

Browse files
committed
Merge branch 'ACP2E-3064' of https://github.com/adobe-commerce-tier-4/magento2-page-builder into T4-PR-06-14-2024
2 parents 62d38d0 + d91b0aa commit 70634ff

File tree

4 files changed

+47
-19
lines changed

4 files changed

+47
-19
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\ViewModel;
9+
10+
use Magento\Backend\ViewModel\RequireJsConfigModifierInterface;
11+
use Magento\Framework\View\Element\Block\ArgumentInterface;
12+
13+
/**
14+
* Modifies requirejs configuration for the stage render frame
15+
*
16+
* Override the text! plugin within the iframe to ensure we can pipe any XHR requests through to the parent window
17+
* as the same origin policy will not allow us to load the templates within this iframe.
18+
* It is important that this mapping is configured before requirejs-config.js to ensure the text! plugin is overridden
19+
* for all requests.
20+
*/
21+
class StageRenderFrameRequireJsConfigModifier implements ArgumentInterface, RequireJsConfigModifierInterface
22+
{
23+
/**
24+
* @inheritDoc
25+
*/
26+
public function modify(array $config): array
27+
{
28+
$config['map']['*'] = array_merge(
29+
$config['map']['*'] ?? [],
30+
[
31+
'text' => 'Magento_PageBuilder/js/master-format/render/requirejs/text',
32+
'Magento_PageBuilder/js/events' => 'Magento_PageBuilder/js/master-format/render/events'
33+
]
34+
);
35+
return $config;
36+
}
37+
}

app/code/Magento/PageBuilder/view/adminhtml/layout/pagebuilder_stage_render.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
<remove src="css/styles.css"/>
1515
</head>
1616
<body>
17+
<referenceBlock name="require.js">
18+
<arguments>
19+
<argument name="config_modifier" xsi:type="object">
20+
Magento\PageBuilder\ViewModel\StageRenderFrameRequireJsConfigModifier
21+
</argument>
22+
</arguments>
23+
</referenceBlock>
1724
<referenceContainer name="backend.page" remove="true"/>
1825
<referenceContainer name="menu.wrapper" remove="true"/>
1926
<referenceContainer name="root">

app/code/Magento/PageBuilder/view/adminhtml/templates/stage/render.phtml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,16 @@
1010
*/
1111
?>
1212

13-
<?php
14-
/**
15-
* Override the text! plugin within the iframe to ensure we can pipe any XHR requests through to the parent window
16-
* as the same origin policy will not allow us to load the templates within this iframe.
17-
*/
18-
?>
1913
<?php
2014
$pageBuilderConfig = $block->getPageBuilderConfig();
2115

22-
$script = <<<SCRIPT
23-
require.config({
24-
'map': {
25-
'*': {
26-
'text': 'Magento_PageBuilder/js/master-format/render/requirejs/text',
27-
'Magento_PageBuilder/js/events': 'Magento_PageBuilder/js/master-format/render/events'
28-
}
29-
}
30-
});
31-
SCRIPT;
32-
3316
/**
3417
* To be able to override the text plugin we need the Magento template engine to be used, as the template engine
3518
* within lib has a dependency on the text! plugin we need to ensure we set the template engine before the
3619
* dependency blocks us. If we try to just override using the RequireJS config above our !text plugin will never
3720
* get overridden as our template engine cannot load.
3821
*/
39-
$script .= <<<SCRIPT
22+
$script = <<<SCRIPT
4023
require([
4124
'ko',
4225
'Magento_Ui/js/lib/knockout/template/engine'

app/code/Magento/PageBuilder/view/adminhtml/web/template/page-builder.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<with args="stage">
3232
<render></render>
3333
</with>
34-
<iframe attr="id: 'render_frame_' + id" sandbox="allow-scripts allow-same-origin" style="position: absolute; width:0; height:0; border: none;"></iframe>
34+
<!-- Do not modify the "sandbox" attribute without approval from a security engineer -->
35+
<iframe attr="id: 'render_frame_' + id" sandbox="allow-scripts" style="position: absolute; width:0; height:0; border: none;"></iframe>
3536
</if>
3637
</div>

0 commit comments

Comments
 (0)