Menu Close
    Searching for an experienced Magento 2 Development Company ?

    Hide Admin Menu Based on System Config in Magento 2

    Hello Readers! In this blog I will show, how you can hide admin menu based on system configuration and module availability in Magento 2.

    This feature is very essential when we are developing a module with multiple features and have option to enable or disable some features. To show menu in admin menu section we write code in menu.xml file which is in Webkul/ModuleName/etc/adminhtml folder. So let’s see how it’s done in below code,

    <?xml version="1.0"?>
    <config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
            <add id="Webkul_ModuleName::mainmenu" title="Main Menu" module="Webkul_ModuleName" sortOrder="10" resource="Webkul_ModuleName::mainmenu"/>
            <add id="Webkul_ModuleName::menu" title="Menu" module="Webkul_ModuleName" sortOrder="10" parent="Webkul_ModuleName::mainmenu" dependsOnModule="Webkul_ModuleName" resource="Webkul_ModuleName::mainmenu"/>
            <add id="Webkul_ModuleName::submenu" title="Sub Menu" module="Webkul_ModuleName" sortOrder="1" parent="Webkul_ModuleName::menu" action="routename" resource="Webkul_ModuleName::submenu" dependsOnConfig="section/group/field"/>

    With the attribute dependsOnModule we can manage visibility of the menu based on availability on any module. And with attribute dependsOnConfig we can manage visibility of the menu based on system config field.

    Thanks for reading the blog. Please comment if you face any issue.

    . . .
    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