I need to create a custom dropdown having values of Enable/Disable in config file in magento 1.9 .How can I achieve this? can anyone help me?
1 Answer 1
Why would you want to create it in config file? Do you want to edit module's configuration settings? If so, you need to do that in system.xml like shown below :
<?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="fme" translate="label" sortOrder="250">
<label>Vendor</label>
</tab>
<section id="vendor_module" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>fme-separator</class>
<label>Article</label>
<tab>fme</tab>
<resource>Vendor_Module::resource_name</resource>
<group id="general" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General</label>
<field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Module Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
It'll make a Module Enable/Disable toggle in your module's configurations. Look under label "General" and in your config.xml you can set default value for this field like below :
<?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>
<vendor_module>
<general>
<enable>1</enable>
</general>
</vendor_module>
</default>
</config>
-
As of now I edited in system.xml file m but how I add <source_model> in system.xml file and how I access while value is selected in dropdown in my files.Mahesh1343– Mahesh13432020年10月23日 12:59:55 +00:00Commented Oct 23, 2020 at 12:59
-
See my edit and tell me if it helps. :)Abdul Samad Abbasi– Abdul Samad Abbasi2020年10月23日 13:07:59 +00:00Commented Oct 23, 2020 at 13:07
-
I answered the question you asked in this thread, if you've another question, you can ask separately so it would help others too. :)Abdul Samad Abbasi– Abdul Samad Abbasi2020年10月23日 13:09:25 +00:00Commented Oct 23, 2020 at 13:09
-
Already , I have one custom module , in that I need a dropdown , as of now I edited the system.xml file in that module and add a dropdown , but for me how I pass the value to the dropdown from model by using <source_model></source_model>Mahesh1343– Mahesh13432020年10月23日 13:10:10 +00:00Commented Oct 23, 2020 at 13:10
-
Like in this site excellencemagentoblog.com/blog/2011/09/22/…Mahesh1343– Mahesh13432020年10月23日 13:13:14 +00:00Commented Oct 23, 2020 at 13:13