Magento 2 - How to add a custom store config in an existing tab?
Yes, we can do this.
We should take a look:
vendor/magento/module-payment/etc/adminhtml/system.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="payment" translate="label" type="text" sortOrder="400" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Payment Methods</label>
<tab>sales</tab>
<resource>Magento_Payment::payment</resource>
</section>
</system>
</config>
The sales
tab was defined from vendor/magento/module-sales/etc/adminhtml/system.xml
. So, when we want to create a new section under SALES tab, we create a new section with <tab>sales</tab>
node.
app/code/Vendor1/Module1/etc/adminhtml/system.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="custom_tab1" translate="label" type="text" sortOrder="401" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Your custom tab 1</label>
<tab>sales</tab>
<resource>Vendor_Module::custom</resource>
</section>
</system>
</config>
Or if we want to add a custom field to an existing section - custom_tab1
. Declare our custom fields inside this section.
app/code/Vendor2/Module2/etc/adminhtml/system.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="custom_tab1">
<group id="custom_group1" translate="label" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Custom Group1</label>
<field id="custom_field1" type="text" translate="label comment" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Custom Field 1</label>
</field>
</group>
</section>
</system>