In this post I am going to explain how to hide admin menu based on system config in Magento 2.
In order to add admin menu we write code in menu.xml file, which is located at <vendor>/<module>/etc/adminhtml/.
So now let’s see how you can hide menu based on conditions. Check the below code snippet.
1 2 3 4 5 6 7 8 9 | <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd"> <menu> <add id="Ht_Mymodule::title" title="Title" module="Ht_Mymodule" sortOrder="10" resource="Ht_Mymodule::title"/> <add id="Ht_Mymodule::menu" title="Menu" module="Ht_Mymodule" sortOrder="10" parent="Ht_Mymodule::title" dependsOnModule="Ht_Mymodule" resource="Ht_Mymodule::menu"/> <add id="Ht_Mymodule::submenu" title="Sub Menu" module="Ht_Mymodule" sortOrder="1" parent="Ht_Mymodule::menu" action="routename" resource="Ht_Mymodule::submenu" dependsOnConfig="mymodulesection/general/enabled"/> </menu> </config> |
We have used below attributes in above code snippet.
dependsOnModule: Used to manage visibility of the menu based on availability on any module.
dependsOnConfig: Used to manage visibility of the menu based on system config field.
Write an article about ecommerce that help people to grow their ecommerce business. You’ll find best ecommerce guide, news, tips & more!
Leave a Reply