|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magefan ([email protected]). All rights reserved. |
| 4 | + * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). |
| 5 | + * |
| 6 | + * Glory to Ukraine! Glory to the heroes! |
| 7 | + */ |
| 8 | + |
| 9 | +declare(strict_types=1); |
| 10 | + |
| 11 | +namespace Magefan\RocketJavaScript\Model\Config\Backend; |
| 12 | + |
| 13 | +use Magento\Framework\App\Config\Value; |
| 14 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 15 | +use Magento\Store\Model\ScopeInterface as StoreScopeInterface; |
| 16 | +use Magento\Framework\App\RequestInterface; |
| 17 | +use Magento\Framework\Model\Context; |
| 18 | +use Magento\Framework\Registry; |
| 19 | +use Magento\Framework\App\Cache\TypeListInterface; |
| 20 | +use Magento\Framework\Model\ResourceModel\AbstractResource; |
| 21 | +use Magento\Framework\Data\Collection\AbstractDb; |
| 22 | + |
| 23 | +class DevSettings extends Value |
| 24 | +{ |
| 25 | + const KEY_VALUE_RELATION = [ |
| 26 | + 'mfrocketjavascript/general/merge_files' => 'dev/js/merge_files', |
| 27 | + 'mfrocketjavascript/general/minify_files' => 'dev/js/minify_files', |
| 28 | + 'mfrocketjavascript/javascript_bundling/enabled' => 'dev/js/enable_js_bundling', |
| 29 | + ]; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var RequestInterface |
| 33 | + */ |
| 34 | + private $request; |
| 35 | + |
| 36 | + /** |
| 37 | + * DevSettings constructor. |
| 38 | + * @param Context $context |
| 39 | + * @param Registry $registry |
| 40 | + * @param ScopeConfigInterface $config |
| 41 | + * @param TypeListInterface $cacheTypeList |
| 42 | + * @param RequestInterface $request |
| 43 | + * @param AbstractResource|null $resource |
| 44 | + * @param AbstractDb|null $resourceCollection |
| 45 | + * @param array $data |
| 46 | + */ |
| 47 | + public function __construct( |
| 48 | + Context $context, |
| 49 | + Registry $registry, |
| 50 | + ScopeConfigInterface $config, |
| 51 | + TypeListInterface $cacheTypeList, |
| 52 | + RequestInterface $request, |
| 53 | + AbstractResource $resource = null, |
| 54 | + AbstractDb $resourceCollection = null, |
| 55 | + array $data = [] |
| 56 | + ) { |
| 57 | + $this->request = $request; |
| 58 | + parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @return DevSettings|void |
| 63 | + */ |
| 64 | + public function afterLoad() |
| 65 | + { |
| 66 | + $scopeTypes = [ |
| 67 | + StoreScopeInterface::SCOPE_WEBSITES, |
| 68 | + StoreScopeInterface::SCOPE_WEBSITE, |
| 69 | + StoreScopeInterface::SCOPE_STORES, |
| 70 | + StoreScopeInterface::SCOPE_STORE |
| 71 | + ]; |
| 72 | + |
| 73 | + $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT; |
| 74 | + $scopeCode = null; |
| 75 | + |
| 76 | + foreach ($scopeTypes as $scope) { |
| 77 | + $param = $this->request->getParam($scope); |
| 78 | + if ($param) { |
| 79 | + $scopeType = $scope; |
| 80 | + $scopeCode = $param; |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + $devSettingsValue = $this->_config->getValue( |
| 85 | + self::KEY_VALUE_RELATION[$this->getData('path')], |
| 86 | + $scopeType, |
| 87 | + $scopeCode |
| 88 | + ); |
| 89 | + $this->setData('value', $devSettingsValue); |
| 90 | + } |
| 91 | +} |
0 commit comments