Create system config in magento 2
Update menu.xml
Rsgitech\News\etc\adminhtml\menu.xml
Add system configuration link in menu
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<add id="Rsgitech_News::rsgitech" title="RSGiTECH" translate="title" module="Rsgitech_News" sortOrder="90" dependsOnModule="Rsgitech_News" resource="Rsgitech_News::rsgitech"/>
<add id="Rsgitech_News::news" title="News" translate="title" module="Rsgitech_News" parent="Rsgitech_News::rsgitech" sortOrder="50" dependsOnModule="Rsgitech_News" resource="Rsgitech_News::news"/>
<add id="Rsgitech_News::news_allnews" title="All News" translate="title" module="Rsgitech_News" parent="Rsgitech_News::news" sortOrder="10" dependsOnModule="Rsgitech_News" action="news/allnews" resource="Rsgitech_News::news_allnews"/>
<add id="Rsgitech_News::settings" title="Settings" translate="title" module="Rsgitech_News" parent="Rsgitech_News::rsgitech" sortOrder="60" dependsOnModule="Rsgitech_News" resource="Rsgitech_News::settings"/>
<add id="Rsgitech_News::news_config" title="Configuration" translate="title" module="Rsgitech_News" parent="Rsgitech_News::settings" sortOrder="10" dependsOnModule="Rsgitech_News" action="adminhtml/system_config/edit/section/rsgitech_news" resource="Rsgitech_News::news_config"/>
</menu>
</config>
Create file system.xml
Rsgitech\News\etc\adminhtml\system.xml
<?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="rsgitech" translate="label" sortOrder="250">
<label>Rsgitech</label>
</tab>
<section id="rsgitech_news" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>rsgitech-separator</class>
<label>News</label>
<tab>rsgitech</tab>
<resource>Rsgitech_News::news_config</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>
<group id="storefront" translate="label" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Storefront</label>
<field id="news_link" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>News Link</label>
<comment>This is news link</comment>
</field>
<field id="set_limit" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Set The Number of Limit</label>
<comment>Set the number of limit for showing latest news</comment>
</field>
</group>
</section>
</system>
</config>
Create file config.xml
Rsgitech\News\etc\config.xml
You can set default value in system configuration
<?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>
<rsgitech_news>
<general>
<enable>1</enable>
</general>
<storefront>
<news_link>Latest News</news_link>
<set_limit>10</set_limit>
</storefront>
</rsgitech_news>
</default>
</config>
0 comments:
Post a Comment
Thanks