Request Quote

Disable Admin Menu item by the configuration value in Magento 2

Here we learn in Magento 2- How we can admin menu items depends 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 System.xml file which is used for the configuration which is located in 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 these on the settings in the configuration.
Create Menu.xml file for the admin menu items which is also located in 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"/>

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

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

Hope it will help you. Thank you.

. . .


Add Your Comment

Be the first to comment.

Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again