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.
Solved! Go to Solution.
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
Cheers, Hope it helps
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:
It says that we can use the following:
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?
i think you should still rethink your idea. as in Magento 2.2.x there is no option to disable module output
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.
Glad to know you have solved your issue , Happy to help and keep helping