Disable/Enable module in magento using system.xml in magento

Disable/Enable module in magento using system.xml in magento

September 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Disable/Enable module in magento using system.xml in magento

Disabling/Enabling Magento Modules Using Custom Configuration via system.xml

As an experienced Magento developer, I often find myself needing to manage modules programmatically rather than through the default admin interface. This guide will walk you through disabling or enabling modules using a custom configuration tab created with system.xml, providing you with a more controlled and integrated user experience.

Understanding Default Magento Module Disabling/Enabling

Before diving into our custom solution, let’s quickly review how to disable/enable modules in the default Magento way:

  1. Navigate to “System” > “Configuration” > “Advanced”.
  2. Under “Disable Modules Output”, find your desired module.
  3. Set active to false for disabling or true for enabling.

This approach is simple but lacks customization and control, especially when dealing with multiple modules or complex configurations.

Creating a Custom Configuration Tab via system.xml

To enable/disable modules via a custom tab, you’ll need to modify your module’s config.xml file. Here’s an example:

<config>
    <modules>
        <Your_Company_Name_Your_Module>
            <version>1.0.0</version>
        </Your_Company_Name_Your_Module>
    </modules>
    <global>
        <stores>
            <store>
                <config>
                    <tab_id>custom_tab</tab_id>
                    <section_id>module_manager</section_id>
                    <sort_order>100</sort_order>
                </config>
            </store>
        </stores>
        <modules>
            <Your_Company_Name_Your_Module>
                <active>true</active>
                <codePool>local</codePool>
                <depends/>
                <autoload>
                    <files>
                        <file type="module">Setup/InstallData.php</file>
                    </files>
                </autoload>
            </Your_Company_Name_Your_Module>
        </modules>
    </global>
</config>

In this example, replace Your_Company_Name_Your_Module with your module’s actual name. This code will create a new configuration tab called “custom_tab” under the “Advanced” section.

Defining Your Custom Configuration Fields

Next, you need to define the fields for enabling/disabling modules within your custom tab. Update your system.xml file as follows:

<config>
    <tabs>
        <custom_tab translate="label" module="your_module">
            <label>Custom Module Manager</label>
        </custom_tab>
    </tabs>

    <sections>
        <module_manager translate="label" module="your_module">
            <label>Module Manager</label>
        </module_manager>
    </sections>

    <groups>
        <group_one translates="label" module="your_module">
            <label>Enabled Modules</label>
        </group_one>
    </groups>

    <fields>
        <field_name translate="label" sort_order="10" show_in_default="1"
          show_in_website="1" is_required="false" module="your_module">
            <label>Module Name</label>
            <input class="validate-select" type="select" source_model="module/list" />
        </field_name>

        <field_enabled translate="label" sort_order="20" show_in_default="1"
          show_in_website="1" is_required="false" module="your_module">
            <label>Enable Module</label>
            <input class="validate-enable" type="select"
              option_value="true" option_label="Yes" />
        </field_enabled>

        <field_disabled translate="label" sort_order="20" show_in_default="1"
          show_in_website="1" is_required="false" module="your_module">
            <label>Disable Module</label>
            <input class="validate-enable" type="select"
              option_value="false" option_label="Yes" />
        </field_disabled>
    </fields>
</config>

This code defines a new group called “group_one” under the custom tab, containing fields for selecting modules and enabling/disabling them.

Implementing the Module Disabling/Enabling Logic

To actually disable or enable a module based on these fields, you’ll need to create an InstallData class in your module. This class should handle the database updates required to set the active flag of each module:

<?php
namespace Your\Company\Name\Your\Module\Setup;

use Magento\Framework\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Cms\Model\WidgetFactory;


class InstallData implements Setup\InstallDataInterface
{
    public function install(Setup\SetupInterface $setup, ModuleContextInterface $context)
    {
        // Implement your installation logic here
        // You can access the setup schema and perform necessary database updates
    }

    protected function disableModule($moduleName)
    {
        // Logic to disable the specified module
        // Update the active flag in the eav_attribute table or relevant configuration tables
    }

    protected function enableModule($moduleName)
    {
        // Logic to enable the specified module
        // Update the active flag in the eav_attribute table or relevant configuration tables
    }
}

In this InstallData class, you would implement your actual disable/enable logic within the disableModule and enableModule methods. These methods should update the appropriate database records to set the active flag for each module.

Conclusion

Disabling or enabling Magento modules using a custom configuration tab via system.xml provides greater control and flexibility in managing your module output. By following this guide, you can create a more integrated user experience within your Magento store’s admin interface while still maintaining the ability to manage modules programmatically.

Remember to replace the placeholders with your actual module details and adjust the logic as needed to fit your specific use case.

For further information on configuration file structure and best practices in Magento development, I recommend exploring the official Magento documentation or visiting Laravel Company.

Extensions Admin Configuration Orders

Our network