Skip to content

Commit 31bd392

Browse files
mrtuvntuna2smc
authored andcommitted
Add logic check only import css from enabled modules
1 parent 96faea7 commit 31bd392

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Framework\Css\PreProcessor\Instruction;
79

810
use Magento\Framework\App\ObjectManager;
@@ -57,25 +59,34 @@ class MagentoImport implements PreProcessorInterface
5759
*/
5860
private $themeProvider;
5961

62+
/**
63+
* @var \Magento\Framework\Module\Manager
64+
*/
65+
private $moduleManager;
66+
6067
/**
6168
* @param DesignInterface $design
6269
* @param CollectorInterface $fileSource
6370
* @param ErrorHandlerInterface $errorHandler
6471
* @param \Magento\Framework\View\Asset\Repository $assetRepo
6572
* @param \Magento\Framework\View\Design\Theme\ListInterface $themeList
73+
* @param \Magento\Framework\Module\Manager|null $moduleManager
6674
*/
6775
public function __construct(
6876
DesignInterface $design,
6977
CollectorInterface $fileSource,
7078
ErrorHandlerInterface $errorHandler,
7179
\Magento\Framework\View\Asset\Repository $assetRepo,
72-
\Magento\Framework\View\Design\Theme\ListInterface $themeList
80+
\Magento\Framework\View\Design\Theme\ListInterface $themeList,
81+
?\Magento\Framework\Module\Manager $moduleManager = null
7382
) {
7483
$this->design = $design;
7584
$this->fileSource = $fileSource;
7685
$this->errorHandler = $errorHandler;
7786
$this->assetRepo = $assetRepo;
7887
$this->themeList = $themeList;
88+
$this->moduleManager = $moduleManager
89+
?? ObjectManager::getInstance()->get(\Magento\Framework\Module\Manager::class);
7990
}
8091

8192
/**
@@ -108,9 +119,16 @@ protected function replace(array $matchedContent, LocalInterface $asset)
108119
$importFiles = $this->fileSource->getFiles($this->getTheme($relatedAsset), $resolvedPath);
109120
/** @var $importFile \Magento\Framework\View\File */
110121
foreach ($importFiles as $importFile) {
122+
$moduleName = $importFile->getModule();
123+
124+
if ($moduleName &&
125+
!$this->moduleManager->isEnabled($moduleName)) {
126+
continue;
127+
}
128+
111129
$referenceString = $isReference ? '(reference) ' : '';
112-
$importsContent .= $importFile->getModule()
113-
? "@import $referenceString'{$importFile->getModule()}::{$resolvedPath}';\n"
130+
$importsContent .= $moduleName
131+
? "@import $referenceString'{$moduleName}::{$resolvedPath}';\n"
114132
: "@import $referenceString'{$matchedFileId}';\n";
115133
}
116134
} catch (\LogicException $e) {

0 commit comments

Comments
 (0)