Read More
Read More
Menu Close

    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.

    Searching for an experienced
    Magento 2 Company ?
    Read More

    Hope it will help you. Thank you.

    . . .
    Discuss on Helpdesk

    Leave a Comment

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

    Be the first to comment.

    Back to Top