-2

I have created two different modules, now I want to create one tab in admin system configuration and show both modules configurations in different tabs.

I have two different modules within same "namespace". i.e. "Mymodule_First" and "Mymodule_Second". both have different functionality.

How can I achieve this?

  • can you update your code what you have tried with detail, it will help to others to give solutions? – Sathish Dec 24 '18 at 11:09
  • @Utsav Gupta are you getting solution or not? – Dhiren Vasoya Dec 25 '18 at 13:20
3

You can check your code or follow below steps.

  • you need create system.xml for both modules

  • use same tab id for both sections

  • use same/different section id for both groups

  • use unique group id for two tabs

app/code/vendor/ModuleA/etc/adminhtml/system.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="custom" translate="label" sortOrder="10">
            <label>Custom Tab</label>
        </tab>
    <section id="firstmenu" translate="label" type="text" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>First Menu</label>
            <tab>custom</tab>
            <resource>Vendor_ModuleA::index</resource>
            <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>General</label>
                <field id="moduleA_key" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>ModuleA Key</label>
                    <comment><![CDATA[Enter your comments]]></comment>
                </field>
            </group>
        </section>
    </system>
</config>

app/code/vendor/ModuleB/etc/adminhtml/system.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
    <section id="secondmenu" translate="label" type="text" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Second Menu</label>
            <tab>custom</tab>
            <resource>Vendor_ModuleB::index</resource>
            <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>General</label>
                <field id="moduleB_key" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>ModuleB Key</label>
                    <comment><![CDATA[Enter your comments]]></comment>
                </field>
            </group>
        </section>
    </system>
</config>

Output:

 --------------
    Custom Tab  ^|
    --------------
    First Menu   |
    -------------
    Second Menu  |

Type 2:

app/code/vendor/ModuleA/etc/adminhtml/system.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="custom" translate="label" sortOrder="10">
            <label>Custom Tab</label>
        </tab>
    <section id="firstmenu" translate="label" type="text" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>First Menu</label>
            <tab>custom</tab>
            <resource>Vendor_ModuleA::index</resource>
            <group id="taba" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Tab 1</label>
                <field id="moduleA_key" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>ModuleA Key</label>
                    <comment><![CDATA[Enter your comments]]></comment>
                </field>
            </group>
        </section>
    </system>
</config>

app/code/vendor/ModuleB/etc/adminhtml/system.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
    <section id="firstmenu" translate="label" type="text" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
            <tab>custom</tab>
            <resource>Vendor_ModuleB::index</resource>
            <group id="tabb" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Tab 2</label>
                <field id="moduleB_key" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>ModuleB Key</label>
                    <comment><![CDATA[Enter your comments]]></comment>
                </field>
            </group>
        </section>
    </system>
</config>

Output:

----------------------------------------------
Custom Tab  ^|   Tab 1                      ^
----------------------------------------------
First Menu   |   Tab 2                      ^
--------------

I hope it will help to achieve your goal

happy coding!

  • do we need to remove the "<tab id="custom" translate="label" sortOrder="10"> <label>Custom Tab</label> </tab>" from second module's system.xml? – Utsav Gupta Dec 24 '18 at 12:10
  • yes if already id defined – Sathish Dec 24 '18 at 12:26
  • I have two different modules within same "namespace". i.e. "Mymodule_First" and "Mymodule_Second". both have different functionality. – Utsav Gupta Dec 24 '18 at 12:38
  • I have drafted 2 type of outputs right? which type of output you expect? – Sathish Dec 24 '18 at 12:39
  • I want to use type 1. – Utsav Gupta Dec 24 '18 at 12:56

Your Answer

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

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