I am trying to enable/disable Magento 2 from admin general setting. I created an option to disabled / enabled module from backend > configuration > module > enable (Yes/No)
when I tried to disabled module functionality still working. Is it a database related issue or another issue.
Secondly, I tried to get check in coding whether module enable or not by followed below steps
Index controller :-
<?php
namespace Vender\Modulename\Controller\Index;
use Magento\Framework\App\Action\Context;
class Index extends \Magento\Framework\App\Action\Action
{
protected $resultJsonFactory;
protected $scopeConfig;
public function __construct(Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory)
{
$this->resultJsonFactory = $resultJsonFactory;
//$this->_helper = $helper;
$this->scopeConfig = $scopeConfig;
parent::__construct($context);
}
protected function helper($className)
{
return $this->_objectManager->get($className);
}
protected function getUrl($path)
{
return $this->_objectManager->get('Magento\Framework\UrlInterface')->getUrl($path);
}
public function execute()
{
//die('dfsd');
//$topTel = $this->_helper->getConfig('dynamicpdf/general/topTel');
//$_thishepler = $this->_helper('Vender\Modulename\Helper\Data');
//$isEnabled = $helper->getStoreConfig('VenderMOdulename/general/enabled');
//print_r($isEnabled); die;
$helper = \Magento\Framework\App\ObjectManager::getInstance()->get('Vendor\modulename\Helper\Data');
echo "<pre>";
//print_r($helper);
if($helper->isEnable()){
}
// My code
}
}
Helper > Data.php
namespace Vendor\Modulename\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Store\Model\ScopeInterface;
class Data extends AbstractHelper
{
protected $context;
public function __construct(Context $context)
{
$this->context = $context;
parent::__construct($context);
}
public function isEnable()
{
return $this->scopeConfig->getValue('modulename/general/enable', ScopeInterface::SCOPE_STORE);
}
}