1

Is it possible to show or hide a tab dynamically within the store configuration menu depending on a condition? I'm writing an extension using an OAuth 2 token, and want to hide tabs in the menu if there's no token. For example, say I want to hide the "Services" menu tab shown below. I know you can hide or show depending on visibility scope (showInWebsite, showInStore, etc.), but I want to show or hide dynamically.

config menu

Here's a portion of my MyCompany/MyModule/etc/adminhtml/system.xml:

<tab id="mycompany" translate="label" sortOrder="500">
            <label>MyCompany Tab</label>
        </tab>
        <section id="mycompany_account" translate="label" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
            <class>separator-top</class>
            <label>Account</label>
            <tab>mycompany</tab>
            <resource>MyCompany_MyModule::settings_configuration</resource>
            <group id="settings" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>Account Settings</label>
                <field id="mycompany_connect_new_account" type="button" translate="button_label" sortOrder="0" showInDefault="1" showInWebsite="0" showInStore="0">
                    <button_label>Create New Account</button_label>
                    <frontend_model>MyCompany\MyModule\Block\Adminhtml\System\Config\Form\Field\CreateNewAccountButton</frontend_model>
                </field>
                <field id="mycompany_connect_production" type="button" translate="button_label" sortOrder="0" showInDefault="1" showInWebsite="0" showInStore="0">
                    <button_label>Connect Account</button_label>
                    <frontend_model>MyCompany\MyModule\Block\Adminhtml\System\Config\Form\Field\ConnectProductionButton</frontend_model>                
                </field>
                <field id="mycompany_connect_sandbox" type="button" translate="button_label" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                    <button_label>Connect Sandbox Account</button_label>
                    <frontend_model>MyCompany\MyModule\Block\Adminhtml\System\Config\Form\Field\ConnectSandboxButton</frontend_model>                
                </field>
                <field id="mycompany_disconnect" translate="button_label" sortOrder="4" showInDefault="1" showInWebsite="0" showInStore="0">
                    <button_label>Disconnect</button_label>
                    <frontend_model>MyCompany\MyModule\Block\Adminhtml\System\Config\Form\Field\DisconnectButton</frontend_model>                
                </field>
                <field id="id" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Login ID</label>
                    <frontend_model>MyCompany\MyModule\Block\Adminhtml\System\Config\Form\Field\Disable</frontend_model>
                </field>
                <field id="token" translate="label" type="text" sortOrder="6" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Access Token</label>
                    <frontend_model>MyCompany\MyModule\Block\Adminhtml\System\Config\Form\Field\Disable</frontend_model>
                </field>
                <field id="server" translate="label" type="text" sortOrder="7" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>API Endpoint</label>
                    <frontend_model>MyCompany\MyModule\Block\Adminhtml\System\Config\Form\Field\Disable</frontend_model>
                </field>
                <field id="community" translate="label" type="select" sortOrder="8" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Community</label>
                    <frontend_model>MyCompany\MyModule\Block\Adminhtml\System\Config\Form\Field\SelectDisable</frontend_model>
                    <source_model>MyCompany\MyModule\Block\Adminhtml\System\Config\Form\Field\CommunitiesSelect</source_model>
                </field>
            </group>
        </section>
  • do you want to hide whole configuration or part of the configuration submenu. It can be done via Acl system->user roles. I am looking to hide menus present within stores->Configuration->sales->Checkout Totals Sort Order if you know about it, please share – insoftservice Jun 24 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.