cancel
Showing results for 
Search instead for 
Did you mean: 

Hide a custom module menu item in admin

SOLVED

Hide a custom module menu item in admin

Hello everyone,

 

I have a custom module that adds a menu item in the admin navigation which is defined in menu.xml.

 

The module also has a configuration screen in store > configuration, which is defined in system.xml. This configuration screen has a parameter to enable/disable the module.

 

How do I make sure the menu item doesn't show when the module is disabled in the configuration screen?

 

Thanks a lot for your answers.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Hide a custom module menu item in admin

Yes that 's true magento 2.2.x onwards disabled module output is removed and its not there .

 

But if you want to achieve this menu hides functionality from enable/disable configuration settings , you need to disabled your module by programatically.

 

Below is the code :

 

$status = $this->objectManager->create('Magento\Framework\Module\Status');
$status->setIsEnabled(false,[$moduleName]);

Where false and true is your configuration value which is enable/disable

You need to pass your module Name for the same.

 

It will disabled your module based on the settings from back-end , and if module is disabled then its menu items also hides from admin.

 

 

if issue solved,Click Kudos & Accept as Solution

View solution in original post

6 REPLIES 6

Re: Hide a custom module menu item in admin

Actually it does not disable module, it disables module output, that's why you see still admin settings. What you can do, is go under System -> User roles -> your user roll and under Roles Resources you can hide custom menu links. I would suggest to uninstall module if you dont use it Smiley Happy 
Cheers, Hope it helps 

Re: Hide a custom module menu item in admin

Thank you for this input. I am actually looking for a way to do this automatically without user action => if the module is disabled (or output is disabled), then the menu link disappears.

 

If found this link for Magento 1:

https://magento.stackexchange.com/questions/10176/possible-to-hide-admin-menu-if-custom-module-is-di...

 

It says that we can use the following:

<depends>

<config>path/to/parameter</config>

</depends> 

However the post doesn't say precisely where to place this, and I haven't managed to make it work on M2. Is there any way we can hide a menu item automatically with this kind of approach?

 

Re: Hide a custom module menu item in admin

i think you should still rethink your idea. as in Magento 2.2.x there is no option to disable module output 

Re: Hide a custom module menu item in admin

Yes that 's true magento 2.2.x onwards disabled module output is removed and its not there .

 

But if you want to achieve this menu hides functionality from enable/disable configuration settings , you need to disabled your module by programatically.

 

Below is the code :

 

$status = $this->objectManager->create('Magento\Framework\Module\Status');
$status->setIsEnabled(false,[$moduleName]);

Where false and true is your configuration value which is enable/disable

You need to pass your module Name for the same.

 

It will disabled your module based on the settings from back-end , and if module is disabled then its menu items also hides from admin.

 

 

if issue solved,Click Kudos & Accept as Solution

Re: Hide a custom module menu item in admin

nice one, thanks a lot!

Re: Hide a custom module menu item in admin

@davidfiaty

 

Glad to know you have solved your issue , Happy to help and keep helping Smiley Happy

if issue solved,Click Kudos & Accept as Solution