Tutorialsplane

Magento 2 create system configuration


Magento 2 create system configuration (system.xml)– It is very simple to create system configuration in Magento 2, it is a little bit different than the magento 1. In magento 2 we need to create some additional files to create system configuration. Here in this tutorial, we are going to explain how you can create system configuration in Magento 2. We are going to create a simple HelloWorld module to explain this functionality, you can directly download this module and use it.


Magento 2 create system configuration Settings Example | Custom System.xml

You need to create the following two files to create system config settings-

Now let us go one by one to create the above files-

1. Create System.xml

First create system.xml file in app/code/Tutorialsplane/HelloWorld/etc/adminhtml/system.xml and then add the following code to create tabs, sections, group and fields-

Magento 2 create system configuration Example:

<?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="helloworld" sortorder="999" translate="label">
			
		</tab>
		<section id="basic_settings" showindefault="1" showinstore="1" showinwebsite="1" sortorder="10" translate="label">
			
			<tab>helloworld</tab>
			<resource>Tutorialsplane_HelloWorld::config_tutorialsplane_helloworld</resource>
			<group id="check" showindefault="1" showinstore="1" showinwebsite="1" sortorder="10" translate="label">
				
				<field id="enabled" showindefault="1" showinstore="1" showinwebsite="1" sortorder="10" translate="label" type="select">
					
					<comment></comment>
					<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
				</field>
			</group>
		</section>
	</system>
</config>

In the above example we have created a simple setting having option – yes/no. On the same way you can create your own settings.

2. Create acl.xml

Now create acl.xml and add the following code –

System Setting acl.xml Example:

<?xml version="1.0" ??>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation="urn:magento:framework:Acl/etc/acl.xsd">
	<acl>
		<resources>
			<resource id="Magento_Backend::admin">
				<resource id="Magento_Backend::stores">
					<resource id="Magento_Backend::stores_settings">
						<resource id="Magento_Config::config">
							<resource id="Tutorialsplane_HelloWorld::config_tutorialsplane_helloworld" title="basic_settings"></resource>
						</resource>
					</resource>
				</resource>
			</resource>
		</resources>
	</acl>
</config>

3. Add default value in config.xml

Now add the default system configuration value in config.xml.

Add default value in config.xml Example:

<?xml version="1.0" ??>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation="urn:magento:module:Magento_Store:etc/config.xsd">
	<default>
		<basic_settings>
			<check>
				<enabled></enabled>
			</check>
		</basic_settings>
	</default>
</config>

In the above example we have created a simple setting for HelloWorld Module, on the same way you can create multiple settings for you module.

Download Sample Module

You can download the sample module simply by clicking this – Tutorialsplane_HelloWorld