4

I would like to add module On/Off option in Configuration for custom extension.

I have used below code and add into my system.xml but when I select option No module is not off.

<field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">
       <label>Enabled</label>
       <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>

Is there any anther code I have to do in other file ?

Or is there wrong in this code ?

3
  • Have you remove var/generataion folder Commented Aug 4, 2017 at 8:55
  • Still not working. Commented Aug 4, 2017 at 9:01
  • are you add condition in xml file ifconfig="sectionid/groupid/fieldid" Commented Aug 4, 2017 at 9:59

1 Answer 1

9

Try below snippet:

<group id="test" translate="label" type="text" sortOrder="350" showInDefault="1" showInWebsite="1" showInStore="0">
    <label>Your Title</label>
    <field id="enable_module" translate="label" type="select" showInDefault="1" canRestore="1">
        <label>Enabled</label>
        <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
    </field>
</group>
4
  • hi @Ashish, how to show default as No Commented Mar 7, 2019 at 14:10
  • Also can you tell me how to read this value? Commented Mar 7, 2019 at 14:21
  • Refre this: magento.stackexchange.com/a/90797/62614 Commented Mar 7, 2019 at 15:10
  • <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> this line show the selelect button option yes/no.. can you guyes please tell me how can button knows module should be off while selelect no and on while select yes.
    – irshad
    Commented Nov 22, 2019 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.