Skip to content

Commit 7704b86

Browse files
authored
Merge pull request #563 from ivanhrytsaim/10568-Check-Hyva-theme
10568-Check-Hyva-theme
2 parents 1555cc4 + b2bf199 commit 7704b86

File tree

3 files changed

+182
-0
lines changed

3 files changed

+182
-0
lines changed

Block/Adminhtml/HyvaThemeChecker.php

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
}

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)