|
| 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\Blog\Block\Adminhtml; |
| 12 | + |
| 13 | +use Magento\Backend\Block\Template; |
| 14 | +use Magento\Backend\Block\Template\Context; |
| 15 | +use Magento\Framework\Module\Manager as ModuleManager; |
| 16 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 17 | +use Magento\Store\Model\StoreManagerInterface; |
| 18 | +use Magento\Framework\View\Design\Theme\ThemeProviderInterface; |
| 19 | +use Magefan\Blog\Model\Config; |
| 20 | +use Magefan\Community\Model\HyvaThemeDetection; |
| 21 | + |
| 22 | +class HyvaThemeChecker extends Template |
| 23 | +{ |
| 24 | + /** |
| 25 | + * @var ModuleManager |
| 26 | + */ |
| 27 | + protected $moduleManager; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var StoreManagerInterface |
| 31 | + */ |
| 32 | + protected $storeManager; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var ScopeConfigInterface |
| 36 | + */ |
| 37 | + protected $scopeConfig; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var ThemeProviderInterface |
| 41 | + */ |
| 42 | + protected $themeProvider; |
| 43 | + |
| 44 | + /** |
| 45 | + * @var HyvaThemeDetection |
| 46 | + */ |
| 47 | + protected $hyvaThemeDetection; |
| 48 | + |
| 49 | + /** |
| 50 | + * @var Config |
| 51 | + */ |
| 52 | + protected $config; |
| 53 | + |
| 54 | + /** |
| 55 | + * Constructor |
| 56 | + * |
| 57 | + * @param Context $context |
| 58 | + * @param ModuleManager $moduleManager |
| 59 | + * @param StoreManagerInterface $storeManager |
| 60 | + * @param ScopeConfigInterface $scopeConfig |
| 61 | + * @param ThemeProviderInterface $themeProvider |
| 62 | + * @param Config $config |
| 63 | + * @param array $data |
| 64 | + */ |
| 65 | + public function __construct( |
| 66 | + Context $context, |
| 67 | + ModuleManager $moduleManager, |
| 68 | + StoreManagerInterface $storeManager, |
| 69 | + ScopeConfigInterface $scopeConfig, |
| 70 | + ThemeProviderInterface $themeProvider, |
| 71 | + Config $config, |
| 72 | + HyvaThemeDetection $hyvaThemeDetection, |
| 73 | + array $data = [] |
| 74 | + ) { |
| 75 | + parent::__construct($context, $data); |
| 76 | + $this->moduleManager = $moduleManager; |
| 77 | + $this->storeManager = $storeManager; |
| 78 | + $this->scopeConfig = $scopeConfig; |
| 79 | + $this->themeProvider = $themeProvider; |
| 80 | + $this->hyvaThemeDetection =$hyvaThemeDetection; |
| 81 | + $this->config = $config; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * @return array |
| 86 | + */ |
| 87 | + public function getWitchModuleIsInstalled(): array |
| 88 | + { |
| 89 | + |
| 90 | + $modules = [ |
| 91 | + 'Magefan_Blog' => 'https://github.com/magefan/hyva-theme-blog', |
| 92 | + 'Magefan_BlogPlus' => 'https://github.com/magefan/hyva-theme-blog-plus', |
| 93 | + 'Magefan_BlogExtra' => 'https://github.com/magefan/hyva-theme-blog-extra', |
| 94 | + 'Magefan_BlogAuthor' => 'https://github.com/magefan/hyva-theme-blog-author', |
| 95 | + 'Magefan_AutoRelatedProduc' => 'https://github.com/magefan/hyva-theme-auto-related-product', |
| 96 | + 'Magefan_AutoRelatedProductPlus' => 'https://github.com/magefan/hyva-theme-auto-related-product-plus', |
| 97 | + 'Magefan_AutoLanguageSwitcher' => 'https://github.com/magefan/hyva-theme-auto-language-switcher' |
| 98 | + ]; |
| 99 | + |
| 100 | + |
| 101 | + $hyvaModules = []; |
| 102 | + foreach ($modules as $module => $url){ |
| 103 | + if ($this->moduleManager->isEnabled($module)) { |
| 104 | + $hyvaModule = 'Hyva_' . str_replace('_', '', $module); |
| 105 | + if (!$this->moduleManager->isEnabled($hyvaModule)) { |
| 106 | + $hyvaModules[$hyvaModule] = $url; |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + return $hyvaModules; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Produce and return block's html output |
| 115 | + * |
| 116 | + * This method should not be overridden. You can override _toHtml() method in descendants if needed. |
| 117 | + * |
| 118 | + * @return string |
| 119 | + */ |
| 120 | + public function toHtml() |
| 121 | + { |
| 122 | + if ($this->config->isEnabled()){ |
| 123 | + if (!$this->hyvaThemeDetection->execute()) { |
| 124 | + return ''; |
| 125 | + } |
| 126 | + |
| 127 | + return parent::toHtml(); |
| 128 | + } |
| 129 | + } |
| 130 | +} |
0 commit comments