How to enable /disble module in admin configuration setting .....
I also refer Magento 2 - add Enable / Disable field for custom module how to enable/disable full module
Thanks....
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityHow to enable /disble module in admin configuration setting .....
I also refer Magento 2 - add Enable / Disable field for custom module how to enable/disable full module
Thanks....
You can add the field Enable/Disable in the System config and use the value entered there.
Check the below example of system config file. It should always be named as system.xml
and put inside the <Module>/etc/adminhtml
directory.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="helloworld" translate="label" sortOrder="100">
<!-- add a new tab with id helloworld -->
<label>Hello World</label>
</tab>
<section id="helloworld" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<!-- add a new section with id helloworld and for tab helloworld -->
<class>separator-top</class>
<label>Hello World Configuration</label>
<tab>helloworld</tab>
<resource>Excellence_First::test_config</resource>
<group id="active_display" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<!-- add a new group with id active display -->
<label>Hello World Configuration Options</label>
<field id="scope" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<!-- add a new field with id scope -->
<label>Enable Helloworld Controller</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
Once you successfully implement the above file you will see the output in the Stores > Configurations
page.
Under the Tab titled "Hello World" you will see the Section "Hello World Configuration", by clicking on it, you will be sent to the configurations page of the module.
Which will have the Dropdown containing Yes and No options. select one of them and the option will be saved in the core_config_data
table in the database.
To get the value in the block or helper or model or Controller or any where, you need to add dependency in the respective class's constructor.
\Magento\Framework\App\Config\ScopeConfigInterface
and assign it to the member variable of the class.
To get the value, you can use $this->scopeConfig->getValue('path/to/field');
For further reference you can use the following links. http://excellencemagentoblog.com/blog/2016/04/10/magento2-system-xml/ https://magento.stackexchange.com/a/87835/16246