Magento – Add multiple sections under same tab magento 2.0

magento2

I want to add multiple sections under the same tab in admin panel. Here is what I have for system.xml (cut off config tag):

<system>
    <!-- Add new Tab -->
    <tab id="xxx" translate="label" sortOrder="5000">
        <label>XXXX</label>
    </tab>
    <section id="ldap" translate="label" type="text" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
        <class>separator-top</class>
        <label>Ldap</label>
        <tab>xxx</tab>
        <!-- resource tag name which we have to defined in the acl.xml -->
        <resource>XXXX_XXXX::config</resource>

        <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>General Options</label>
            <field id="active" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Enabled</label>
            </field>
        </group>
    </section>
    <section id="smtp" translate="label" type="text" sortOrder="140" showInDefault="1" showInWebsite="1" showInStore="1">
        <class>separator-top</class>
        <label>SMTP</label>
        <tab>xxx</tab>
        <!-- resource tag name which we have to defined in the acl.xml -->
        <resource>XXXX_XXXX::config</resource>

        <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>General Options</label>
            <field id="active" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Enabled</label>
            </field>
        </group>
    </section>
</system>

and acl.xml:

<acl>
    <resources>
        <resource id="Magento_Backend::admin">
            <resource id="Magento_Backend::stores">
                <resource id="Magento_Backend::stores_settings">
                    <resource id="Magento_Config::config">
                        <!-- this resource id we can use in system.xml for section -->
                        <resource id="XXXX_XXXX::config" title="Ldap" sortOrder="10" />
                    </resource>
                </resource>
            </resource>
        </resource>
    </resources>
</acl>

The error shows "Warning: Invalid argument supplied for foreach() in /var/www/magento2/vendor/magento/module-config/Model/Config/Structure/Mapper/Sorting.php on line 34"

Best Answer

The problem arises because the section id should be unique across the whole application. So I changed the id and it works.

Related Topic