Skip to content

Commit ef601ca

Browse files
committed
Add min resolver to render after requirejs.
This is needed for editing to work while minification is enabled. Otherwise, it attempts to load bad URLs that won't exist. Note: this must be after require.min.js.
1 parent a80fe04 commit ef601ca

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

app/code/Magento/PageBuilder/Block/Adminhtml/Stage/Render.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace Magento\PageBuilder\Block\Adminhtml\Stage;
1010

11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\View\Asset\Minification;
1113
use Magento\Framework\View\Element\Template;
1214
use Magento\RequireJs\Model\FileManager;
1315
use Magento\PageBuilder\Model\Stage\Config;
@@ -33,24 +35,32 @@ class Render extends Template
3335
*/
3436
private $json;
3537

38+
/**
39+
* @var Minification
40+
*/
41+
private $minification;
42+
3643
/**
3744
* @param Template\Context $context
3845
* @param FileManager $fileManager
3946
* @param Config $config
4047
* @param Json $json
4148
* @param array $data
49+
* @param Minification $minification
4250
*/
4351
public function __construct(
4452
Template\Context $context,
4553
FileManager $fileManager,
4654
Config $config,
4755
Json $json,
48-
array $data = []
56+
array $data = [],
57+
Minification $minification = null
4958
) {
5059
parent::__construct($context, $data);
5160
$this->fileManager = $fileManager;
5261
$this->pageBuilderConfig = $config;
5362
$this->json = $json;
63+
$this->minification = $minification ?: ObjectManager::getInstance()->get(Minification::class);
5464
}
5565

5666
/**
@@ -65,6 +75,20 @@ public function getRequireJsUrl() : string
6575
return $asset->getUrl();
6676
}
6777

78+
/**
79+
* Generate the URL to the RequireJS min resolver, if minification enabled.
80+
*
81+
* @return string|null
82+
*/
83+
public function getRequireJsMinUrl() : ?string
84+
{
85+
if ($this->minification->isEnabled('js')) {
86+
$minResolverAsset = $this->fileManager->createMinResolverAsset();
87+
return $minResolverAsset->getUrl();
88+
}
89+
return null;
90+
}
91+
6892
/**
6993
* Retrieve the URL to the RequireJS Config file
7094
*

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
/** @var \Magento\PageBuilder\Block\Adminhtml\Stage\Render $block */
88
?>
99
<script src="<?= $block->escapeUrl($block->getRequireJsUrl()); ?>"></script>
10+
<?php if ($block->getRequireJsMinUrl()) : ?>
11+
<script src="<?= $block->escapeUrl($block->getRequireJsMinUrl()); ?>"></script>
12+
<?php endif; ?>
1013
<script src="<?= $block->escapeUrl($block->getRequireJsConfigUrl()); ?>"></script>
1114
<script>
1215
<?php

0 commit comments

Comments
 (0)