Question

In my custom module system.xml I added

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
    <tab id="Customodule" translate="label" sortOrder="10">
        <label>Settings</label>
    </tab>
    <section id="ConnSettings" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
        <label>Connection Settings</label>
        <tab>Customodule</tab>
        <resource>Vendor_Customodule::config</resource>
        <group id="first" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">

<field id="accessLevel" translate="label" type="radios" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Access Level</label>
    <source_model>Vendor\CustomModule\Model\Source\AccessLevel</source_model>
</field>

Model file is as

class AccessLevel implements \Magento\Framework\Option\ArrayInterface
{
    public function toOptionArray()
    {

        return  [
                    [
                        'value' => 'test', 
                        'label' => __('Testing')
                    ], 
                    [
                        'value' => 'production', 
                        'label' => __('Production')
                    ],
                ];
    }

}

I want to select Test option by default.

What should I do please reply me!!!

Was it helpful?

Solution

Add this code in your config.xml :

<?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>
        <ConnSettings>
            <first>
                <accessLevel>test</accessLevel>
            </first>
        </ConnSettings>
    </default>
</config>

Remove value from core_config_data table and upgrade and deploy.

OTHER TIPS

Please add following code in your etc/config.xml

<?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>
       <ConnSettings>
            <first>
                <accessLevel>test</accessLevel>
            </first>
       </ConnSettings>
   </default>
</config>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top