0

How to hide top menu and disable my custom module, if field "enabled" is 0(no). Magento version 1.9

<?xml version="1.0"?>
<config>
<tabs>
    <plumrocket translate="title">
        <label>Plumrocket</label>
        <sort_order>10</sort_order>
    </plumrocket>
</tabs>
<sections>
    <productlabels translate="title">
        <label>Product Labels</label>
        <tab>plumrocket</tab>
        <backend_model>productlabels/system</backend_model>
        <show_in_default>1</show_in_default>
        <show_in_Website>1</show_in_Website>
        <show_in_store>1</show_in_store>
        <groups>
            <global>
                <label translate="title">Settings</label>
                <sort_order>10</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_Website>1</show_in_Website>
                <show_in_store>1</show_in_store>
                <fields>
                    <enabled>
                        <label translate="title">Enabled</label>
                        <frontend_type>select</frontend_type>
                        <source_model>adminhtml/system_config_source_yesno</source_model>
                        <sort_order>20</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_Website>1</show_in_Website>
                        <show_in_store>1</show_in_store>
                    </enabled>
                </fields>
            </global>
        </groups>
    </productlabels>
</sections>

1
  • Why you don't disable the module from xml file under app/etc/modules? it will remove every configurations from the admin. Commented Feb 27, 2018 at 0:19

2 Answers 2

0

In your etc/adminhtml.xml, in which you define your top menu item, you can use the <depends></depends> node in the same way as you would do in system.xml to make one option depend on another one.

This means, in your etc/adminhtml.xml you can do something like this (note: you need to adapt vendor_module by yourself as it is not declared in your question):

<adminhtml>
    <menu>
        <vendor_module module="vendor_module">
            <depends>
                <config>productlabels/global/enabled</config> <!-- as defined in your system.xml -->
            </depends>
            <title>Vendor Module Title</title>
            <sort_order>71</sort_order>               
            <action>vendor_module/adminhtml_something</action>
        </vendor_module>
    </menu>
</adminhtml>

The magic part in this is the <depends><config>productlabels/global/enabled</config></depends> which makes Magento check for whether this option is set to Yes or No in System -> Configuration -> Your Module -> Your Option.

Important note: This does not mean that your controller action is not reachable! If you want to hinder the user to reach the page behind by entering its direct URL you'll have to cover this separately.

2
  • Thank you, it working but section in top menu make hidden when i am refrashe cache. I try clean cache on event "admin_system_config_changed_section_productlabels" but i dont know how do it. Commented Feb 27, 2018 at 8:06
  • I'm sorry, @ПетроЧайківський, I think I can not follow. You mean you set the visibility flag to "no" but the menu item is still visible until you clear the cache? Commented Feb 28, 2018 at 0:54
0

This is not the top menu, it's configuration settings, but you can hide them by commenting on the <tab> ... </ tab> tag. Then the Magento will not know which module these settings belong to. The top menu settings are in the <menu>

5
  • it menu in System>Configuration, there is field "enabled", when endbled equal 0 i need hide the one section from top menu Commented Feb 26, 2018 at 23:08
  • you need to use jQuery, hide the field, if at change (), value = 0. Commented Feb 26, 2018 at 23:15
  • bad idea and i dont know how to use jQuery in Magento Commented Feb 26, 2018 at 23:17
  • write jquery in the template that connects to the page. jQuery is already connected Commented Feb 26, 2018 at 23:20
  • @EvgeniyKapelko - jQuery as such is interpreted in the browser, hence you would need to view the modules settings page in order to be able to hide a top menu item. Any other page would show the menu item anyway, since you can not refer to something that is not present in the html output in this way. Commented Feb 27, 2018 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.