|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magefan ([email protected]). All rights reserved. |
| 4 | + * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php). |
| 5 | + * |
| 6 | + * Glory to Ukraine! Glory to the heroes! |
| 7 | + */ |
| 8 | + |
| 9 | +namespace Magefan\Blog\Block\Adminhtml\System\Config\Form; |
| 10 | + |
| 11 | +/** |
| 12 | + * Class CheckEnableInfo |
| 13 | + * @package Magefan\Blog\Block\Adminhtml\System\Config\Form |
| 14 | + */ |
| 15 | +class CheckEnableInfo extends \Magento\Backend\Block\Template |
| 16 | +{ |
| 17 | + /** |
| 18 | + * Magefan Blog Plus |
| 19 | + */ |
| 20 | + const MAGEFAN_BLOG_PLUS = 'Magefan_BlogPlus'; |
| 21 | + |
| 22 | + /** |
| 23 | + * Extension key config path |
| 24 | + */ |
| 25 | + const XML_PATH_KEY = 'mfblog/general/key'; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var \Magefan\Blog\Model\Config |
| 29 | + */ |
| 30 | + protected $config; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var \Magento\Store\Model\StoreManagerInterface |
| 34 | + */ |
| 35 | + protected $_storeManager; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var \Magento\Framework\Module\ModuleListInterface |
| 39 | + */ |
| 40 | + protected $moduleList; |
| 41 | + |
| 42 | + /** |
| 43 | + * @var \Magento\Framework\App\ProductMetadataInterface |
| 44 | + */ |
| 45 | + protected $metadata; |
| 46 | + |
| 47 | + /** |
| 48 | + * CheckEnableInfo constructor. |
| 49 | + * @param \Magento\Backend\Block\Template\Context $context |
| 50 | + * @param \Magefan\Blog\Model\Config $config |
| 51 | + * @param \Magento\Store\Model\StoreManagerInterface $storeManager |
| 52 | + * @param \Magento\Framework\Module\ModuleListInterface $moduleList |
| 53 | + * @param \Magento\Framework\App\ProductMetadataInterface $metadata |
| 54 | + * @param array $data |
| 55 | + */ |
| 56 | + public function __construct( |
| 57 | + \Magento\Backend\Block\Template\Context $context, |
| 58 | + \Magefan\Blog\Model\Config $config, |
| 59 | + \Magento\Store\Model\StoreManagerInterface $storeManager, |
| 60 | + \Magento\Framework\Module\ModuleListInterface $moduleList, |
| 61 | + \Magento\Framework\App\ProductMetadataInterface $metadata, |
| 62 | + array $data = [] |
| 63 | + ) { |
| 64 | + $this->config = $config; |
| 65 | + $this->_storeManager = $storeManager; |
| 66 | + $this->moduleList = $moduleList; |
| 67 | + $this->metadata = $metadata; |
| 68 | + parent::__construct($context, $data); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @return bool |
| 73 | + */ |
| 74 | + public function isEnabled() |
| 75 | + { |
| 76 | + foreach ($this->_storeManager->getWebsites() as $website) { |
| 77 | + foreach ($website->getGroups() as $group) { |
| 78 | + $stores = $group->getStores(); |
| 79 | + if (count($stores) == 0) { |
| 80 | + continue; |
| 81 | + } |
| 82 | + |
| 83 | + foreach ($stores as $store) { |
| 84 | + if ($this->config->isEnabled($store->getId())) { |
| 85 | + return true; |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + return false; |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * @return bool |
| 96 | + */ |
| 97 | + public function isKeyMissing() |
| 98 | + { |
| 99 | + return !$this->config->getConfig(self::XML_PATH_KEY) |
| 100 | + && ($this->metadata->getEdition() != 'Community' |
| 101 | + || $this->moduleList->has(self::MAGEFAN_BLOG_PLUS) |
| 102 | + ); |
| 103 | + } |
| 104 | +} |
0 commit comments