Skip to content

Commit d3f5c94

Browse files
author
Oleksandr Iegorov
committed
MC-29033: admin catalog can't load css in the cloud
1 parent e3e85a1 commit d3f5c94

File tree

3 files changed

+141
-10
lines changed

3 files changed

+141
-10
lines changed

lib/internal/Magento/Framework/View/Asset/Minification.php

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function addMinifiedSign($filename)
8383
{
8484
$extension = pathinfo($filename, PATHINFO_EXTENSION);
8585

86-
if ($this->isEnabled($extension) &&
86+
if ($this->isEnabledForArea($filename) &&
8787
!$this->isExcluded($filename) &&
8888
!$this->isMinifiedFilename($filename)
8989
) {
@@ -102,7 +102,7 @@ public function removeMinifiedSign($filename)
102102
{
103103
$extension = pathinfo($filename, PATHINFO_EXTENSION);
104104

105-
if ($this->isEnabled($extension) &&
105+
if ($this->isEnabledForArea($filename) &&
106106
!$this->isExcluded($filename) &&
107107
$this->isMinifiedFilename($filename)
108108
) {
@@ -180,4 +180,49 @@ private function getMinificationExcludeValues($key)
180180
}
181181
return array_values($configValues);
182182
}
183+
184+
/**
185+
* Check whether asset minification is on for specified content type and for area
186+
*
187+
* @param string $filename
188+
* @return bool
189+
*/
190+
private function isEnabledForArea(string $filename): bool
191+
{
192+
$area = $this->getAreaFromPath($filename);
193+
$extension = pathinfo($filename, PATHINFO_EXTENSION);
194+
195+
if ($area !== 'adminhtml') {
196+
$result = $this->isEnabled($extension);
197+
} else {
198+
$cacheConfigKey = $area . '_' . $extension;
199+
if (!isset($this->configCache[self::XML_PATH_MINIFICATION_ENABLED][$cacheConfigKey])) {
200+
$this->configCache[self::XML_PATH_MINIFICATION_ENABLED][$cacheConfigKey] =
201+
$this->appState->getMode() != State::MODE_DEVELOPER &&
202+
$this->scopeConfig->isSetFlag(
203+
sprintf(self::XML_PATH_MINIFICATION_ENABLED, $extension),
204+
'default'
205+
);
206+
}
207+
208+
$result = $this->configCache[self::XML_PATH_MINIFICATION_ENABLED][$cacheConfigKey];
209+
}
210+
return $result;
211+
}
212+
213+
/**
214+
* Get area from the path
215+
*
216+
* @param string $filename
217+
* @return string
218+
*/
219+
private function getAreaFromPath(string $filename): string
220+
{
221+
$area = '';
222+
$pathParts = explode('/', $filename);
223+
if (!empty($pathParts) && isset($pathParts[0])) {
224+
$area = $pathParts[0];
225+
}
226+
return $area;
227+
}
183228
}

lib/internal/Magento/Framework/View/Asset/PreProcessor/MinificationFilenameResolver.php

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Framework\View\Asset\PreProcessor;
77

88
use Magento\Framework\View\Asset\Minification;
9+
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Framework\App\State;
911

1012
/**
1113
* Class MinificationFilenameResolver
@@ -22,14 +24,31 @@ class MinificationFilenameResolver implements FilenameResolverInterface
2224
*/
2325
private $minification;
2426

27+
/**
28+
* @var State
29+
*/
30+
private $appState;
31+
32+
/**
33+
* @var ScopeConfigInterface
34+
*/
35+
private $scopeConfig;
36+
2537
/**
2638
* Constructor
2739
*
2840
* @param Minification $minification
41+
* @param ScopeConfigInterface $scopeConfig
42+
* @param State $appState
2943
*/
30-
public function __construct(Minification $minification)
31-
{
44+
public function __construct(
45+
Minification $minification,
46+
ScopeConfigInterface $scopeConfig,
47+
State $appState
48+
) {
3249
$this->minification = $minification;
50+
$this->scopeConfig = $scopeConfig;
51+
$this->appState = $appState;
3352
}
3453

3554
/**
@@ -40,10 +59,35 @@ public function __construct(Minification $minification)
4059
*/
4160
public function resolve($path)
4261
{
43-
if (!$this->minification->isEnabled(pathinfo($path, PATHINFO_EXTENSION))) {
44-
return $path;
62+
$result = $path;
63+
if ($this->isEnabledForArea($path)) {
64+
$result = str_replace(self::FILE_PART, '.', $path);
4565
}
4666

47-
return str_replace(self::FILE_PART, '.', $path);
67+
return $result;
68+
}
69+
70+
/**
71+
* Check whether asset minification is on for specified content type and for area
72+
*
73+
* @param string $filename
74+
* @return bool
75+
*/
76+
private function isEnabledForArea(string $filename): bool
77+
{
78+
$extension = pathinfo($filename, PATHINFO_EXTENSION);
79+
$result = $this->minification->isEnabled($extension);
80+
$pathParts = explode('/', $filename);
81+
if (!empty($pathParts) && isset($pathParts[0])) {
82+
$area = $pathParts[0];
83+
if ($area === 'adminhtml') {
84+
$result = $this->appState->getMode() != State::MODE_DEVELOPER &&
85+
$this->scopeConfig->isSetFlag(
86+
sprintf(Minification::XML_PATH_MINIFICATION_ENABLED, $extension),
87+
'default'
88+
);
89+
}
90+
}
91+
return $result;
4892
}
4993
}

lib/internal/Magento/Framework/View/Asset/PreProcessor/Minify.php

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Framework\View\Asset\Minification;
1010
use Magento\Framework\View\Asset\PreProcessor;
1111
use Magento\Framework\View\Asset\PreProcessorInterface;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\App\State;
1214

1315
/**
1416
* Assets minification pre-processor
@@ -25,14 +27,30 @@ class Minify implements PreProcessorInterface
2527
*/
2628
protected $minification;
2729

30+
/**
31+
* @var State
32+
*/
33+
private $appState;
34+
35+
/**
36+
* @var ScopeConfigInterface
37+
*/
38+
private $scopeConfig;
39+
2840
/**
2941
* @param AdapterInterface $adapter
3042
* @param Minification $minification
3143
*/
32-
public function __construct(AdapterInterface $adapter, Minification $minification)
33-
{
44+
public function __construct(
45+
AdapterInterface $adapter,
46+
Minification $minification,
47+
ScopeConfigInterface $scopeConfig,
48+
State $appState
49+
) {
3450
$this->adapter = $adapter;
3551
$this->minification = $minification;
52+
$this->scopeConfig = $scopeConfig;
53+
$this->appState = $appState;
3654
}
3755

3856
/**
@@ -43,12 +61,36 @@ public function __construct(AdapterInterface $adapter, Minification $minificatio
4361
*/
4462
public function process(PreProcessor\Chain $chain)
4563
{
46-
if ($this->minification->isEnabled(pathinfo($chain->getTargetAssetPath(), PATHINFO_EXTENSION)) &&
64+
if ($this->isEnabledForArea($chain->getTargetAssetPath()) &&
4765
$this->minification->isMinifiedFilename($chain->getTargetAssetPath()) &&
4866
!$this->minification->isMinifiedFilename($chain->getOrigAssetPath())
4967
) {
5068
$content = $this->adapter->minify($chain->getContent());
5169
$chain->setContent($content);
5270
}
5371
}
72+
73+
/**
74+
* Check whether asset minification is on for specified content type and for area
75+
*
76+
* @param string $filename
77+
* @return bool
78+
*/
79+
private function isEnabledForArea(string $filename): bool
80+
{
81+
$extension = pathinfo($filename, PATHINFO_EXTENSION);
82+
$result = $this->minification->isEnabled($extension);
83+
$pathParts = explode('/', $filename);
84+
if (!empty($pathParts) && isset($pathParts[0])) {
85+
$area = $pathParts[0];
86+
if ($area === 'adminhtml') {
87+
$result = $this->appState->getMode() != State::MODE_DEVELOPER &&
88+
$this->scopeConfig->isSetFlag(
89+
sprintf(Minification::XML_PATH_MINIFICATION_ENABLED, $extension),
90+
'default'
91+
);
92+
}
93+
}
94+
return $result;
95+
}
5496
}

0 commit comments

Comments
 (0)