In this post I am going to explain how to Set Default Values for System Configuration Fields in Magento 2. First we will make one “system.xml” file at below path. Path: app/code/<vendor>/<module>/etc/adminhtml/system.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?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="ht" translate="label" sortOrder="999999"> <label>HT</label> </tab> <section id="mymodulesection" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1"> <class>separator-top</class> <label>My Module</label> <tab>ht</tab> <resource>Magento_Config::config_admin</resource> <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>General</label> <field id="enabled" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Enabled</label> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> </field> <field id="welcome_text" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Welcome Text</label> </field> </group> </section> </system> </config> |
Now, we need to set default values for above system config fields. For that add one file “config.xml” at below path. Path:…
Recent Comments