How to Create System.xml Configuration In Magento 2

Magento 2 is a feature-rich platform with default functionalities suitable for E-commerce businesses. However, with the evolving nature of shopping online and types of businesses, the default Magento 2 falls short. Fortunately, due to the customization capability of the platform, the store owners can use Magento 2 extensions to implement additional functionalities.

Now, there are many extensions where the store owner or admin has to configure a few settings and for which one needs to create system.xml configuration in Magento 2.

Allow the admin to flexibly configure the module by offering fields at Admin Panel > Stores > Configuration.

Example:

System.xml

Create system.xml configuration file in Magento 2 with the below code:

Steps to create system.xml configuration in Magento 2:

Create system.xml file at appcodeVendorExtensionetcadminhtml

<?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="vendor" translate="label" class="vendor" sortOrder="100">
            <label>vendor</label>
        </tab>
        <section id="extension" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1"
                 showInStore="1">
            <class>separator-top</class>
            <label>Extension</label>
            <tab>vendor</tab>
            <resource>Vendor_Extension::config_extension</resource>
            <group id="general" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1"
                   showInStore="1">
                <label>Configuration</label>
                <field id="enable" translate="label comment" type="select" sortOrder="10" showInDefault="1"
                       showInWebsite="1" showInStore="1">
                    <label>Extension Enable</label>
                    <source_model>Magento\Config\Model\Config\Source\Enabledisable</source_model>
                </field>
            </group>
        </section>    
    </system>
</config>

That’s it.

Please share the solution with fellow Magento developers via social media.

Thank you.

Table of Contents