Magento – Remove Admin Menu Item When Module Disabled

menumodule

I developing magento module which creates menu in admin panel. But when I disable it I would like not to show it. I saw this question : Possible to hide admin menu if custom module is disabled? I added the code to my module file (to see if this method is working) in my adminhtml.xml

<config>
    <menu>
    <depends>
         <config>payment/checkmo/active</config>
        </depends>

and then went to System->Configuration->Payment methods and disabled payment method Check/money order ?

What did I do wrong? What config path should be to check if my module is enabled ?

Thanks in advance.

Best Answer

Your code appears to be one level too far up in the xml it should look as follows:

<config>
    <menu>
        <menu-type> <!-- e.g. <catalog> -->
            <depends>
                <config>payment/checkmo/active</config>
            </depends>
        </menu-type>
    </menu>
<config>

Note the missing menu-type node from your original code snippet.

If you look into the database table core_config_data for the path you will see that the entry is set to 1 when the module is disabled from the advanced tab. This means that the code that normally works for the menu will sadly not work for disabling modules via the admin config section and will in fact disable the menu item when the module is active.

The best suggestion would be to do the disable on the main module active flag and then change the module to active/inactive via the xml file under app/etc/modules. The following will remove the menu item when Example_Module is disabled.

<depends>
    <module>Example_Module</module>
</depends>
Related Topic