Skip to content

Commit c1347fa

Browse files
ihor-svizievtuna2smc
authored andcommitted
#32922 Add logic check only import css from enabled modules
Make deploying only enabled modules with flag static_content_only_enabled_modules
1 parent 6949d13 commit c1347fa

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

lib/internal/Magento/Framework/Css/PreProcessor/Instruction/MagentoImport.php

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77

88
namespace Magento\Framework\Css\PreProcessor\Instruction;
99

10+
use Magento\Framework\App\DeploymentConfig;
1011
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\Css\PreProcessor\ErrorHandlerInterface;
13+
use Magento\Framework\Module\Manager as ModuleManager;
1214
use Magento\Framework\View\Asset\File\FallbackContext;
1315
use Magento\Framework\View\Asset\LocalInterface;
1416
use Magento\Framework\View\Asset\PreProcessorInterface;
17+
use Magento\Framework\View\Asset\Repository as AssetRepository;
18+
use Magento\Framework\View\Design\Theme\ListInterface as ThemeListInterface;
1519
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
20+
use Magento\Framework\View\Design\ThemeInterface;
1621
use Magento\Framework\View\DesignInterface;
1722
use Magento\Framework\View\File\CollectorInterface;
1823

@@ -28,6 +33,8 @@ class MagentoImport implements PreProcessorInterface
2833
const REPLACE_PATTERN =
2934
'#//@magento_import(?P<reference>\s+\(reference\))?\s+[\'\"](?P<path>(?![/\\\]|\w:[/\\\])[^\"\']+)[\'\"]\s*?;#';
3035

36+
private const CONFIG_PATH_SCD_ONLY_ENABLED_MODULES = 'static_content_only_enabled_modules';
37+
3138
/**
3239
* @var DesignInterface
3340
*/
@@ -44,12 +51,12 @@ class MagentoImport implements PreProcessorInterface
4451
protected $errorHandler;
4552

4653
/**
47-
* @var \Magento\Framework\View\Asset\Repository
54+
* @var AssetRepository
4855
*/
4956
protected $assetRepo;
5057

5158
/**
52-
* @var \Magento\Framework\View\Design\Theme\ListInterface
59+
* @var ThemeListInterface
5360
* @deprecated 100.0.2
5461
*/
5562
protected $themeList;
@@ -60,33 +67,40 @@ class MagentoImport implements PreProcessorInterface
6067
private $themeProvider;
6168

6269
/**
63-
* @var \Magento\Framework\Module\Manager
70+
* @var DeploymentConfig
71+
*/
72+
private $deploymentConfig;
73+
74+
/**
75+
* @var ModuleManager
6476
*/
6577
private $moduleManager;
6678

6779
/**
6880
* @param DesignInterface $design
6981
* @param CollectorInterface $fileSource
7082
* @param ErrorHandlerInterface $errorHandler
71-
* @param \Magento\Framework\View\Asset\Repository $assetRepo
72-
* @param \Magento\Framework\View\Design\Theme\ListInterface $themeList
73-
* @param \Magento\Framework\Module\Manager|null $moduleManager
83+
* @param AssetRepository $assetRepo
84+
* @param ThemeListInterface $themeList
85+
* @param DeploymentConfig|null $deploymentConfig
86+
* @param ModuleManager|null $moduleManager
7487
*/
7588
public function __construct(
7689
DesignInterface $design,
7790
CollectorInterface $fileSource,
7891
ErrorHandlerInterface $errorHandler,
79-
\Magento\Framework\View\Asset\Repository $assetRepo,
80-
\Magento\Framework\View\Design\Theme\ListInterface $themeList,
81-
?\Magento\Framework\Module\Manager $moduleManager = null
92+
AssetRepository $assetRepo,
93+
ThemeListInterface $themeList,
94+
?DeploymentConfig $deploymentConfig = null,
95+
?ModuleManager $moduleManager = null
8296
) {
8397
$this->design = $design;
8498
$this->fileSource = $fileSource;
8599
$this->errorHandler = $errorHandler;
86100
$this->assetRepo = $assetRepo;
87101
$this->themeList = $themeList;
88-
$this->moduleManager = $moduleManager
89-
?? ObjectManager::getInstance()->get(\Magento\Framework\Module\Manager::class);
102+
$this->deploymentConfig = $deploymentConfig ?? ObjectManager::getInstance() ->get(DeploymentConfig::class);
103+
$this->moduleManager = $moduleManager ?? ObjectManager::getInstance()->get(ModuleManager::class);
90104
}
91105

92106
/**
@@ -117,12 +131,12 @@ protected function replace(array $matchedContent, LocalInterface $asset)
117131
$relatedAsset = $this->assetRepo->createRelated($matchedFileId, $asset);
118132
$resolvedPath = $relatedAsset->getFilePath();
119133
$importFiles = $this->fileSource->getFiles($this->getTheme($relatedAsset), $resolvedPath);
134+
$deployOnlyEnabled = (bool)$this->deploymentConfig->get(self::CONFIG_PATH_SCD_ONLY_ENABLED_MODULES);
120135
/** @var $importFile \Magento\Framework\View\File */
121136
foreach ($importFiles as $importFile) {
122137
$moduleName = $importFile->getModule();
123138

124-
if ($moduleName &&
125-
!$this->moduleManager->isEnabled($moduleName)) {
139+
if ($moduleName && $deployOnlyEnabled && !$this->moduleManager->isEnabled($moduleName)) {
126140
continue;
127141
}
128142

@@ -141,7 +155,7 @@ protected function replace(array $matchedContent, LocalInterface $asset)
141155
* Get theme model based on the information from asset
142156
*
143157
* @param LocalInterface $asset
144-
* @return \Magento\Framework\View\Design\ThemeInterface
158+
* @return ThemeInterface
145159
*/
146160
protected function getTheme(LocalInterface $asset)
147161
{

0 commit comments

Comments
 (0)