Skip to content

Commit f52d3a2

Browse files
committed
10568-Check-Hyva-theme
1 parent 5d3336c commit f52d3a2

File tree

3 files changed

+204
-0
lines changed

3 files changed

+204
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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+
class HyvaThemeChecker extends Template
21+
{
22+
/**
23+
* @var ModuleManager
24+
*/
25+
protected $moduleManager;
26+
27+
/**
28+
* @var StoreManagerInterface
29+
*/
30+
protected $storeManager;
31+
32+
/**
33+
* @var ScopeConfigInterface
34+
*/
35+
protected $scopeConfig;
36+
37+
/**
38+
* @var ThemeProviderInterface
39+
*/
40+
protected $themeProvider;
41+
42+
/**
43+
* @var Config
44+
*/
45+
protected $config;
46+
47+
/**
48+
* Constructor
49+
*
50+
* @param Context $context
51+
* @param ModuleManager $moduleManager
52+
* @param StoreManagerInterface $storeManager
53+
* @param ScopeConfigInterface $scopeConfig
54+
* @param ThemeProviderInterface $themeProvider
55+
* @param Config $config
56+
* @param array $data
57+
*/
58+
public function __construct(
59+
Context $context,
60+
ModuleManager $moduleManager,
61+
StoreManagerInterface $storeManager,
62+
ScopeConfigInterface $scopeConfig,
63+
ThemeProviderInterface $themeProvider,
64+
Config $config,
65+
array $data = []
66+
) {
67+
parent::__construct($context, $data);
68+
$this->moduleManager = $moduleManager;
69+
$this->storeManager = $storeManager;
70+
$this->scopeConfig = $scopeConfig;
71+
$this->themeProvider = $themeProvider;
72+
$this->config = $config;
73+
}
74+
75+
/**
76+
* @return array
77+
*/
78+
public function getWitchModuleIsInstalled(): array
79+
{
80+
81+
$modules = [
82+
'Magefan_Blog' => 'https://github.com/magefan/hyva-theme-blog',
83+
'Magefan_BlogPlus' => 'https://github.com/magefan/hyva-theme-blog-plus',
84+
'Magefan_BlogExtra' => 'https://github.com/magefan/hyva-theme-blog-extra',
85+
'Magefan_BlogAuthor' => 'https://github.com/magefan/hyva-theme-blog-author',
86+
'Magefan_AutoRelatedProduc' => 'https://github.com/magefan/hyva-theme-auto-related-product',
87+
'Magefan_AutoRelatedProductPlus' => 'https://github.com/magefan/hyva-theme-auto-related-product-plus',
88+
'Magefan_AutoLanguageSwitcher' => 'https://github.com/magefan/hyva-theme-auto-language-switcher'
89+
];
90+
91+
92+
$hyvaModules = [];
93+
foreach ($modules as $module => $url){
94+
if ($this->moduleManager->isEnabled($module)) {
95+
$hyvaModule = 'Hyva_' . str_replace('_', '', $module);
96+
if (!$this->moduleManager->isEnabled($hyvaModule)) {
97+
$hyvaModules[$hyvaModule] = $url;
98+
}
99+
}
100+
}
101+
return $hyvaModules;
102+
}
103+
104+
/**
105+
* @return bool
106+
*/
107+
private function isHyvaThemeInUse(): bool
108+
{
109+
$hyvaThemeEnabled = $this->moduleManager->isEnabled('Hyva_Theme');
110+
// $hyvaThemeEnabled = true;
111+
if ($hyvaThemeEnabled) {
112+
$stores = $this->storeManager->getStores();
113+
114+
foreach ($stores as $store) {
115+
$storeId = $store->getId();
116+
$themeId = $this->scopeConfig->getValue(
117+
\Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID,
118+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
119+
$storeId
120+
);
121+
if ($themeId) {
122+
$theme = $this->themeProvider->getThemeById($themeId);
123+
$theme->getThemePath();
124+
$themePath = $theme->getThemePath();
125+
if (false !== stripos($themePath, 'hyva')) {
126+
return true;
127+
}
128+
}
129+
}
130+
}
131+
132+
return false;
133+
}
134+
135+
/**
136+
* Produce and return block's html output
137+
*
138+
* This method should not be overridden. You can override _toHtml() method in descendants if needed.
139+
*
140+
* @return string
141+
*/
142+
public function toHtml()
143+
{
144+
if ($this->config->isEnabled()){
145+
if (!$this->isHyvaThemeInUse()) {
146+
return '';
147+
}
148+
149+
return parent::toHtml();
150+
}
151+
}
152+
}

view/adminhtml/layout/default.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
/**
4+
* Copyright © Magefan ([email protected]). All rights reserved.
5+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
6+
*
7+
* Glory to Ukraine! Glory to the heroes!
8+
*/
9+
-->
10+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
11+
<body>
12+
<referenceContainer name="page.wrapper">
13+
<block class="Magefan\Blog\Block\Adminhtml\HyvaThemeChecker" name="magefan.blog.hyvathemechecker" template="Magefan_Blog::themechecker.phtml" after="header"/>
14+
</referenceContainer>
15+
</body>
16+
</page>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
<?php
10+
/**
11+
* Help template
12+
*
13+
* @var $block \Magefan\Blog\Block\Adminhtml\HyvaThemeChecker
14+
*/
15+
?>
16+
<?php if ($items = $block->getWitchModuleIsInstalled()) { ?>
17+
<div class="messages">
18+
<div class="message message-notice notice">
19+
<div data-ui-id="messages-message-notice" class="linv">
20+
<?= $block->escapeHtml(__('It looks like you are using the Hyva theme, ' .
21+
'but the Hyva Magefan Blog extensions for Hyva compatibility are not installed. ' .
22+
'Please install these modules for the proper functioning of the blog module on the Hyva theme:')) ?>
23+
<div style="margin-left: 30px">
24+
<br/>
25+
<ul>
26+
<?php foreach ($items as $name => $url) { ?>
27+
<li>
28+
<a href="<?= $block->escapeHtml($url) ?>" target="_blank"><?= $block->escapeHtml($name) ?></a>
29+
</li>
30+
<?php } ?>
31+
</ul>
32+
</div>
33+
</div>
34+
</div>
35+
</div>
36+
<?php } ?>

0 commit comments

Comments
 (0)