diff --git a/Helper/Config.php b/Helper/Config.php index d583af5..656f42d 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -6,6 +6,7 @@ use Magento\Framework\App\Helper\Context; use Magento\Framework\App\State; use Magento\Framework\App\RequestInterface; +use Magento\Framework\Exception\LocalizedException; class Config extends AbstractHelper { @@ -18,6 +19,7 @@ class Config extends AbstractHelper { * @var State */ protected State $state; + private array $allowModuleNames; /** * @param Context $context @@ -27,28 +29,28 @@ class Config extends AbstractHelper { public function __construct( Context $context, RequestInterface $request, - State $state + State $state, + array $allowModuleNames = [] ) { $this->request = $request; $this->state = $state; - return parent::__construct($context); + $this->allowModuleNames = $allowModuleNames; + parent::__construct($context); } public function optimizeRequireJsConfig() { try { $areaCode = $this->state->getAreaCode(); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $areaCode = 'cli'; + } catch (LocalizedException $e) { + return true; } - if ( - $areaCode === 'cli' || - $areaCode === 'frontend' && - ($this->request->getModuleName() === "cms" || $this->request->getModuleName() === "catalog") + if ($areaCode === 'frontend' + && in_array($this->request->getModuleName(), $this->allowModuleNames) ) { return true; } + return false; } - } diff --git a/etc/di.xml b/etc/di.xml index b8c202c..c2401d4 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -7,4 +7,12 @@ + + + + cms + catalog + + +