Yes, In magento 2 we can create system configuration file same as Magento 1. But we need to create some file. Lets start how to create it
We need to use following file to create it.
app/code/Webmull/Helloworld/etc/adminhtml/system.xml
app/code/Webmull/Helloworld/etc/acl.xml
This 2 files are important to create system configuration.
In System.xml file
Adding the common content
1 2 3 4 5 6 7 8 9 10 11 12 |
<?xml version="1.0"?> <!-- /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd"> <system> ....... </system> </config> |
Now we need to add the Tab
1 2 3 4 5 6 7 8 |
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd"> <system> <!-- Add new Tab --> <tab id="webmull" translate="label" sortOrder="300"> <label>Webmull Extension</label> </tab> </system> </config> |
Add new Section in the file
1 2 3 4 5 6 |
<section id="helloworld" translate="label" type="text" sortOrder="140" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Helloworld</label> <tab>webmull</tab> <!-- resource tag name which we have to defined in the acl.xml --> <resource>Webmull_Helloworld::config_helloworld</resource> </section> |
Create new group and field on section in file
1 2 3 4 5 6 7 |
<group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <label>General Options</label> <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Enabled</label> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> </field> </group> |
So now System.xml file should display like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?xml version="1.0"?> <!-- /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd"> <system> <!-- Add new Tab --> <tab id="webmull" translate="label" sortOrder="300"> <label>Webmull Extension</label> </tab> <section id="helloworld" translate="label" type="text" sortOrder="140" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Helloworld</label> <tab>webmull</tab> <!-- resource tag name which we have to defined in the acl.xml --> <resource>Webmull_Helloworld::config_helloworld</resource> <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <label>General Options</label> <field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Enabled</label> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> </field> </group> </section> </system> </config> |
Now we need to create acl.xml file
In the file we need to write the below content
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?xml version="1.0"?> <!-- /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/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"> <!-- this resource id we can use in system.xml for section --> <resource id="Webmull_Helloworld::config_helloworld" title="Helloworld Section" sortOrder="80" /> </resource> </resource> </resource> </resource> </resources> </acl> </config> |
After that, Clear the magento cache & logout from admin side. Then Login at admin side. In store >> Configuration you can see the tab “Webmull Extension”. When you click on this you can see the detail of this.
We hope, It will helpful to you.