Back to Top

Disable Admin Menu item by the configuration value in Magento 2

Updated 22 February 2024

Here we learn in Magento 2- How we can admin menu items depending on the configuration value.
If you want to create the custom module configuration in the configuration section, you can check the wonderful blog from here.

1) Create a system.xml file which is used for the configuration which is located in the etc/adminhtml folder of the module.

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
        <tab id="webkul" translate="label" sortOrder="10">
        <section id="test" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Test Configuration</label>
            <group id="settings" translate="label" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <field id="enable" translate="label comment" sortOrder="1" type="select" showInDefault="1" >

2) When you’re adding custom menu items in the admin, you can depend on these on the settings in the configuration.
Create a menu.xml file for the admin menu items which is also located in the etc/adminhtml folder of the module.

<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    	<add id="Webkul_Test::manager" title="Test Manager" module="Webkul_Test" sortOrder="10" resource="Webkul_Test::manager"/>
        <add id="Webkul_Test::test" title="Test Menu" module="Webkul_Test" sortOrder="1" parent="Webkul_Test::manager" action="test/test/index" resource="Webkul_Test::test" dependsOnConfig="test/settings/enable"/>

Here, Webkul_Test is the name of the custom module.

In the add tag, there is an attribute dependsOnConfig which depends on the configuration field’s value.
If the Enable field value is yes then “Test Menu” will show otherwise menu item will not show in the module menus.

Searching for an experienced
Magento 2 Company ?
Find out More

If you want to create a custom module admin menu, you can check the blog from here.

Hope it will help you. Thank you.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home