Skip to content

Commit 3d9a1e4

Browse files
authored
Merge pull request #248 from magefan/2147-fix
2147-check-blog-enable [Implemented]
2 parents ce045ea + c24762c commit 3d9a1e4

File tree

6 files changed

+182
-4
lines changed

6 files changed

+182
-4
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan (support@magefan.com). 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+
}

Block/Adminhtml/System/Config/Form/Info.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,41 @@
1515
*/
1616
class Info extends \Magento\Config\Block\System\Config\Form\Field
1717
{
18+
/**
19+
* Magefan Blog Plus
20+
*/
21+
const MAGEFAN_BLOG_PLUS = 'Magefan_BlogPlus';
22+
1823
/**
1924
* @var \Magento\Framework\Module\ModuleListInterface
2025
*/
2126
protected $moduleList;
2227

2328
/**
29+
* @var \Magento\Framework\App\ProductMetadataInterface
30+
*/
31+
protected $metadata;
32+
33+
/**
34+
* Info constructor.
2435
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
2536
* @param \Magento\Backend\Block\Template\Context $context
2637
* @param array $data
38+
* @param null|\Magento\Framework\App\ProductMetadataInterface
2739
*/
2840
public function __construct(
2941
\Magento\Framework\Module\ModuleListInterface $moduleList,
3042
\Magento\Backend\Block\Template\Context $context,
31-
array $data = []
43+
array $data = [],
44+
$metadata = null
3245
) {
3346
parent::__construct($context, $data);
34-
$this->moduleList = $moduleList;
47+
$this->moduleList = $moduleList;
48+
49+
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
50+
$this->metadata = $metadata ?: $objectManager->get(
51+
\Magento\Framework\App\ProductMetadataInterface::class
52+
);
3553
}
3654

3755
/**
@@ -43,8 +61,19 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
4361
{
4462
$m = $this->moduleList->getOne($this->getModuleName());
4563
$html = '<div style="padding:10px;background-color:#f8f8f8;border:1px solid #ddd;margin-bottom:7px;">
46-
Blog Extension v' . $m['setup_version'] . ' was developed by <a href="https://magefan.com?utm_source=m2admin_blog_config&utm_medium=link&utm_campaign=regular" target="_blank">Magefan</a>.
64+
Blog Extension v' . $m['setup_version'] . ' was developed by <a href="https://magefan.com?utm_source=m2admin_blog_config&utm_medium=link&utm_campaign=regular" target="_blank">Magefan</a>.
4765
</div>';
66+
$html .= '<style>#row_mfblog_general_key{display:none}</style>';
67+
if ($this->metadata->getEdition() != 'Community' || $this->moduleList->has(self::MAGEFAN_BLOG_PLUS)) {
68+
$html .= '<script>
69+
require([
70+
"jquery",
71+
"domReady!"
72+
], function($){
73+
$("#row_mfblog_general_key").show();
74+
});
75+
</script>';
76+
}
4877

4978
return $html;
5079
}

etc/adminhtml/system.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
<label>Enable Extension</label>
2828
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2929
</field>
30+
<field id="key" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="0" showInStore="0">
31+
<label>Product Key</label>
32+
<comment><![CDATA[
33+
You can find product key in your <a href="https://magefan.com/downloadable/customer/products/" target="_blank">Magefan account</a>.
34+
]]></comment>
35+
</field>
3036
</group>
3137
<group id="index_page" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
3238
<label>Blog Index Page</label>

etc/config.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<default>
1212
<mfblog>
1313
<general>
14-
<enabled>1</enabled>
14+
<enabled>0</enabled>
15+
<mfmodule>Blog</mfmodule>
16+
<mftype>1</mftype>
1517
</general>
1618
<index_page>
1719
<title>Blog</title>

view/adminhtml/layout/blog_update_info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</referenceContainer>
1515
<referenceContainer name="content">
1616
<block class="Magefan\Blog\Block\Adminhtml\System\Config\Form\UpdateInfo" name="blog.update.info" template="Magefan_Blog::updateinfo.phtml"/>
17+
<block class="Magefan\Blog\Block\Adminhtml\System\Config\Form\CheckEnableInfo" name="blog.check.enable.info" template="Magefan_Blog::checkenableinfo.phtml"/>
1718
</referenceContainer>
1819
</body>
1920
</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 (support@magefan.com). 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+
<?php
10+
/**
11+
* Blog available for to get notification
12+
*
13+
* @var $block \Magefan\Blog\Block\Adminhtml\System\Config\Form\CheckEnableInfo
14+
*/
15+
?>
16+
<?php if (!$block->isEnabled()) { ?>
17+
<div class="messages">
18+
<div class="message message-error">
19+
<div data-ui-id="messages-message-error">
20+
<?php $html = __('Magefan Blog is disabled, to enable the extension please navigate to <a href="%1" target="_blank">Stores > Configuration > Magefan Extensions > Blog</a>.', $block->getUrl('adminhtml/system_config/edit', ['section' => 'mfblog']));
21+
?>
22+
<?= $html ?>
23+
</div>
24+
</div>
25+
</div>
26+
<?php } elseif ($block->isKeyMissing()) { ?>
27+
<div class="messages">
28+
<div class="message message-error">
29+
<div data-ui-id="messages-message-error">
30+
<?php $html = __('Magefan Blog <strong>Product Key</strong> is missing. Blog Extension will be automatically disabled soon. Please specify the product key in <a href="%1" target="_blank">Stores > Configuration > Magefan Extensions > Blog</a>.', $block->getUrl('adminhtml/system_config/edit', ['section' => 'mfblog']));
31+
?>
32+
<?= $html ?>
33+
</div>
34+
</div>
35+
</div>
36+
<?php } ?>

0 commit comments

Comments
 (0)