I want to add Enable/disable functionality in my custom module by which the module can be enabled or disable directly form admin-panel for just selecting.

I want to add something like this in my custom module enter image description here


This type of functionality does not exist at Magento.

If you want to develop this functionality on your module then you have to add an If conditions of checking this system configuration field on every code of this module. That is too complex and too tough to implement this logic on any module code.

Also, Implementation of this system field checking on a module totally depends on the module code and its business logic and how the business logic is implemented On the code.

Be a developer, my suggestion, you cannot possibly implement this type of enable/disable of a module from admin

  • Oh, I think I misunderstood his question – fmsthird Jan 15 at 12:50
  • Sorry, what is mean of requirement – Amit Bera Jan 15 at 12:52

Modify this files based on your module (update module namespace)


  <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="admin_system_config_changed_section_yourmodulename">
        <observer name="vendor_yourmodulename_disable" instance="Vendor\YourModuleName\Observer\DisableOutput" />


namespace Vendor\YourModuleName\Observer;

use Magento\Config\Model\ResourceModel\Config;

class DisableOutput implements \Magento\Framework\Event\ObserverInterface

const VENDOR_CONFIG = 'yourmodulename/general/enable';

 * @var \Magento\Config\Model\ResourceModel\Config
protected $_config;

 * @var \Magento\Framework\App\Config\ScopeConfigInterface
protected $_scopeConfig;

 * @var \Magento\Store\Model\StoreManagerInterface
protected $storeManager;

 * DisableOutput constructor.
 * @param \Magento\Config\Model\ResourceModel\Config $_config
 * @param \Magento\Framework\App\Config\ScopeConfigInterface $_scopeConfig
 * @param \Magento\Store\Model\StoreManagerInterface $storeManager
 * @param \Magento\Framework\App\RequestInterface $request
public function  __construct(
    Config $_config,
    \Magento\Framework\App\Config\ScopeConfigInterface $_scopeConfig,
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    \Magento\Framework\App\RequestInterface $request
    $this->_config = $_config;
    $this->_scopeConfig = $_scopeConfig;
    $this->storeManager = $storeManager;
    $this->request = $request;


 * @param \Magento\Framework\Event\Observer $observer
public function execute(\Magento\Framework\Event\Observer $observer)
    $disable = false;
    $scopeType = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
    $scopeCode = 0;

        $scopeType = ScopeInterface::SCOPE_STORE;
        $scopeCode = $this->storeManager->getStore($this->request->getParam(\Magento\Store\Model\ScopeInterface::SCOPE_STORE))->getCode();
        $scopeType = ScopeInterface::SCOPE_WEBSITE;
        $scopeCode = $this->storeManager->getWebsite($this->request->getParam(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE))->getCode();
        $scopeType = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
        $scopeCode = 0;
    $moduleConfig= $this->_scopeConfig->getValue(self::VENDOR_CONFIG, $scopeType);

    if((int)$moduleConfig == 0){
        $disable = true;

    $moduleName = 'Vendor_YourModuleName';
    $outputPath = "advanced/modules_disable_output/$moduleName";

    $this->_config->saveConfig($outputPath,$disable, $scopeType,$scopeCode);


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
        <section id="yourmodulename" translate="label" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Enable Module</label>


<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        <add id="Vendor_YourModuleName::yourmodulename_configuration"
             parent="Vendor_YourModuleName::yourmodulename" />
  • Hi @Guxholli Did the above code is worked for you. – shivashankar m May 17 at 10:08
  • Yes it worked @shivashankarm – Ylgen Guxholli May 20 at 8:33
  • Thanks for your reply @Ylgen, i have lot of files in my module, Is there any need to add above functionality for every file. – shivashankar m May 27 at 10:13
  • @shivashankarm i didnt understand your question . Explain in more details – Ylgen Guxholli Jun 14 at 7:32
  • nice one but pay attention as this is going to disable the "output" functionalities only. all the others functionalities will work as usual, so the only way is to disable via module:config – Antonio Pedicini Jul 9 at 12:34

Create a system Config file in your custom module

You can do like this (Assuming your custom module name is "Sample Shipping"



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <section id="carriers" translate="label" type="text" sortOrder="320" showInDefault="1" showInWebsite="1" showInStore="1">
        <group id="sampleShipping" translate="label" type="text" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Sample Shipping</label>
            <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Creating those files in your custom module will enable you to disable/enable your custom module in
Stores > Sales > Shipping method configuration

  • Thanks For help! Yes Your code creating the option for Enable and disable, but it seems not working, when I change the status module always remains at same status – Akash Agrawal Jan 15 at 13:16
  • @AkashAgrawal after implementing above code you need to write php code in your class to make sure if module is enabled. – Abid Malik Oct 10 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.