Magento2 : how to create admin page with configuration fieldsUse Website/Default checkbox for Mage_Adminhtml_Block_Widget_Form fieldLoad jQuery in admin panel programmaticallyAdminhtml new custom Tab in the config section is not showing upMultiple fields per row in Magento admin edit formMagento 2 : How can I upload files of dynamically added file input fields in the adminMagento 2 : Forms in FrontendHow to create a repeater field (like Minsaleqty, Regexceptions) inside admin form in Magento 2?Magento2: Adding custom fields on checkout are not associated with the formMagento2: How to create different home pageMagento2 Admin Side Custom configuration page with a menu
Proof that the inverse image of a single element is a discrete space
Was there ever any real use for a 6800-based Apple I?
Why can't RGB or bicolour LEDs produce a decent yellow?
Can I make ravioli dough with only all-purpose flour or do I NEED semolina flour?
Size of a folder with du
"Right on the tip of my tongue" meaning?
Is the schwa sound consistent?
Anatomically Correct Carnivorous Tree
Why do Thanos's punches not kill Captain America or at least cause some mortal injuries?
How does Howard Stark know this?
How are Core iX names like Core i5, i7 related to Haswell, Ivy Bridge?
How to compact two the parabol commands in the following example?
51% attack - apparently very easy? refering to CZ's "rollback btc chain" - How to make sure such corruptible scenario can never happen so easily?
Why was Thor doubtful about his worthiness to Mjolnir?
What does a comma mean inside an 'if' statement?
How are one-time password generators like Google Authenticator different from having two passwords?
Can the sorting of a list be verified without comparing neighbors?
Make all the squares explode
Meaning of「〜てみたいと思います」
Why does my circuit work on a breadboard, but not on a perfboard? I am new to soldering
How to slow yourself down (for playing nice with others)
For the erase-remove idiom, why is the second parameter necessary which points to the end of the container?
How do I compare the result of "1d20+x, with advantage" to "1d20+y, without advantage", assuming x < y?
Setting the major mode of a new buffer interactively
Magento2 : how to create admin page with configuration fields
Use Website/Default checkbox for Mage_Adminhtml_Block_Widget_Form fieldLoad jQuery in admin panel programmaticallyAdminhtml new custom Tab in the config section is not showing upMultiple fields per row in Magento admin edit formMagento 2 : How can I upload files of dynamically added file input fields in the adminMagento 2 : Forms in FrontendHow to create a repeater field (like Minsaleqty, Regexceptions) inside admin form in Magento 2?Magento2: Adding custom fields on checkout are not associated with the formMagento2: How to create different home pageMagento2 Admin Side Custom configuration page with a menu
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a module which adds a menu in backend linked to a custom page using a controller. All this works fine.
I would like now to use this new admin page for configuration.
I thought using my /view/adminhtml/templates/newpage.phtml
to add all the mandatory fields, but all the entered parameters may be memorized somewhere surely in database.
Is there a dedicated table for that or may I create a new
one ?
Thank you for your help
EDIT : I found I need to use system.xml. But each time in the examples I found, the new configuration fields are in admin/store/configuration menu. Is there a way to define my custom page instead?
magento2 adminhtml
add a comment |
I have a module which adds a menu in backend linked to a custom page using a controller. All this works fine.
I would like now to use this new admin page for configuration.
I thought using my /view/adminhtml/templates/newpage.phtml
to add all the mandatory fields, but all the entered parameters may be memorized somewhere surely in database.
Is there a dedicated table for that or may I create a new
one ?
Thank you for your help
EDIT : I found I need to use system.xml. But each time in the examples I found, the new configuration fields are in admin/store/configuration menu. Is there a way to define my custom page instead?
magento2 adminhtml
For configuration, should usecore_config_data
table.
– Khoa TruongDinh
May 6 '17 at 6:49
add a comment |
I have a module which adds a menu in backend linked to a custom page using a controller. All this works fine.
I would like now to use this new admin page for configuration.
I thought using my /view/adminhtml/templates/newpage.phtml
to add all the mandatory fields, but all the entered parameters may be memorized somewhere surely in database.
Is there a dedicated table for that or may I create a new
one ?
Thank you for your help
EDIT : I found I need to use system.xml. But each time in the examples I found, the new configuration fields are in admin/store/configuration menu. Is there a way to define my custom page instead?
magento2 adminhtml
I have a module which adds a menu in backend linked to a custom page using a controller. All this works fine.
I would like now to use this new admin page for configuration.
I thought using my /view/adminhtml/templates/newpage.phtml
to add all the mandatory fields, but all the entered parameters may be memorized somewhere surely in database.
Is there a dedicated table for that or may I create a new
one ?
Thank you for your help
EDIT : I found I need to use system.xml. But each time in the examples I found, the new configuration fields are in admin/store/configuration menu. Is there a way to define my custom page instead?
magento2 adminhtml
magento2 adminhtml
edited Oct 12 '17 at 4:34
Rohan Hapani
1
1
asked May 6 '17 at 6:40
AlexglvrAlexglvr
90011139
90011139
For configuration, should usecore_config_data
table.
– Khoa TruongDinh
May 6 '17 at 6:49
add a comment |
For configuration, should usecore_config_data
table.
– Khoa TruongDinh
May 6 '17 at 6:49
For configuration, should use
core_config_data
table.– Khoa TruongDinh
May 6 '17 at 6:49
For configuration, should use
core_config_data
table.– Khoa TruongDinh
May 6 '17 at 6:49
add a comment |
1 Answer
1
active
oldest
votes
The system.xml is a configuration file which is used to create configuration fields in Magento 2 System Configuration.
You will need this if your module has some settings which the admin needs to set. You can go to Store -> Setting -> Configuration to check how it look like.
To Create system.xml
- Step 1: Create System.xml
- Step 2: Set default value
- Step 3: Flush Magento cache
- Step 4: Get value from configuration
app/code/Mageplaza/HelloWorld/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="mageplaza" translate="label" sortOrder="10">
<label>Mageplaza</label>
</tab>
<section id="helloworld" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Hello World</label>
<tab>mageplaza</tab>
<resource>Mageplaza_HelloWorld::hello_configuration</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>General Configuration</label>
<field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Module Enable</label>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
</field>
<field id="display_text" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Display Text</label>
<comment>This text will display on the frontend.</comment>
</field>
</group>
</section>
</system>
</config>
Checking this code, you will see how to create a Tab, Section, Group and Field. We will find more detail about each element:
The Tab element may have many sections and some main attributes and child:
Id attribute is the identify for this tab
sortOrder attribute will define the position of this tab.
Translate attribute let Magento know which title need to translate
Label element child is the text which will show as tab title.
The Section element will have id, sortOrder, translate attributes like the Tab element. Some other attributes (showInDefault, showInWebsite, showInStore) will decide this element will be show on each scope or not. You can change the scope here
The section may have many group and some other child elements:
Class: this value will be added as class for this element. You should you it if you want to make-up this element.
Label: the text title of this element
Tab: this’s a tab id. This tab element will let Magento know the tab which this section is belong to. This section will be placed under that tab
Resource: defined the ACL rule which the admin user must have in order to access this configuration.
Group: This element may have many field and some attributes which is same as Sections.
Fields: is the main path of this page. It will save the data which we want to setting. In this element, we focus on the type attribute. It will define how the element is when display. It can be: text, select, file… In this example we create 2 fields with type select and text. With each type we will define the child element for the field to make it work as we want.
For example, with the type select/multiselect you must define the child element resource_model.
Step 2: Set default value
Each field in system.xml after create will not have any value. When you call them, you will receive ‘null’ result. So for the module, we will need to set the default value for the field and you will call the value without go to config, set value and save it. This default value will be saved in config.xml which is located in etc folder. Let’s create it for this simple configuration:
app/code/Mageplaza/HelloWorld/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>
<hello>
<general>
<enable>1</enable>
<display_text>Hello World</display_text>
</general>
</hello>
</default>
</config>
Note that, if you might get an Error 404 Page Not Found first time, just logout and login again to fix this
Step 3: Flush Magento Cache
https://www.mageplaza.com/kb/how-flush-enable-disable-cache.html
Step 4: Get value from configuration
First all of let’s save value and flush cache, then you can get saved value from database.
In the system.xml, we have added 2 fields: enable and display_text. So the path should be:
helloworld/general/enable
helloworld/general/display_text
$this->scopeConfig->getValue('helloworld/general/enable', MagentoStoreModelScopeInterface::SCOPE_STORE);
$this->scopeConfig->getValue('helloworld/general/display_text', MagentoStoreModelScopeInterface::SCOPE_STORE);
For more information use this link
thank you for your answer. is there a way to display my new configuration fields in my adminpage instead of Store -> Setting -> Configuration ?
– Alexglvr
May 6 '17 at 7:02
you want to create new page that store module configuration details instead of magento default page or you want to just display configuration option tab in your module menu
– Vaibhav Ahalpara
May 6 '17 at 7:06
I need to add several configuration fields for my module, but I would prefer not to add them in Store -> Setting -> Configuration. Therefore I create a menu which is linked to a new admin page. I would like to have my own configuration fields in this new page. I found that : magestore.com/magento-2-tutorial/… but seems to be quite complicated compared to the system.xml solution...
– Alexglvr
May 6 '17 at 7:13
There is 2 way to do this first you have to create form/admin page and save this page data to custome database and second you need to save that data to core_config_data table magento save configuration form data in core_config_data table
– Vaibhav Ahalpara
May 6 '17 at 7:17
I managed to create my configuration form. I now would like a yes/no or check box input field to enable/disable another field. Is it possible?
– Alexglvr
May 9 '17 at 10:06
|
show 2 more comments
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f173286%2fmagento2-how-to-create-admin-page-with-configuration-fields%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The system.xml is a configuration file which is used to create configuration fields in Magento 2 System Configuration.
You will need this if your module has some settings which the admin needs to set. You can go to Store -> Setting -> Configuration to check how it look like.
To Create system.xml
- Step 1: Create System.xml
- Step 2: Set default value
- Step 3: Flush Magento cache
- Step 4: Get value from configuration
app/code/Mageplaza/HelloWorld/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="mageplaza" translate="label" sortOrder="10">
<label>Mageplaza</label>
</tab>
<section id="helloworld" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Hello World</label>
<tab>mageplaza</tab>
<resource>Mageplaza_HelloWorld::hello_configuration</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>General Configuration</label>
<field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Module Enable</label>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
</field>
<field id="display_text" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Display Text</label>
<comment>This text will display on the frontend.</comment>
</field>
</group>
</section>
</system>
</config>
Checking this code, you will see how to create a Tab, Section, Group and Field. We will find more detail about each element:
The Tab element may have many sections and some main attributes and child:
Id attribute is the identify for this tab
sortOrder attribute will define the position of this tab.
Translate attribute let Magento know which title need to translate
Label element child is the text which will show as tab title.
The Section element will have id, sortOrder, translate attributes like the Tab element. Some other attributes (showInDefault, showInWebsite, showInStore) will decide this element will be show on each scope or not. You can change the scope here
The section may have many group and some other child elements:
Class: this value will be added as class for this element. You should you it if you want to make-up this element.
Label: the text title of this element
Tab: this’s a tab id. This tab element will let Magento know the tab which this section is belong to. This section will be placed under that tab
Resource: defined the ACL rule which the admin user must have in order to access this configuration.
Group: This element may have many field and some attributes which is same as Sections.
Fields: is the main path of this page. It will save the data which we want to setting. In this element, we focus on the type attribute. It will define how the element is when display. It can be: text, select, file… In this example we create 2 fields with type select and text. With each type we will define the child element for the field to make it work as we want.
For example, with the type select/multiselect you must define the child element resource_model.
Step 2: Set default value
Each field in system.xml after create will not have any value. When you call them, you will receive ‘null’ result. So for the module, we will need to set the default value for the field and you will call the value without go to config, set value and save it. This default value will be saved in config.xml which is located in etc folder. Let’s create it for this simple configuration:
app/code/Mageplaza/HelloWorld/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>
<hello>
<general>
<enable>1</enable>
<display_text>Hello World</display_text>
</general>
</hello>
</default>
</config>
Note that, if you might get an Error 404 Page Not Found first time, just logout and login again to fix this
Step 3: Flush Magento Cache
https://www.mageplaza.com/kb/how-flush-enable-disable-cache.html
Step 4: Get value from configuration
First all of let’s save value and flush cache, then you can get saved value from database.
In the system.xml, we have added 2 fields: enable and display_text. So the path should be:
helloworld/general/enable
helloworld/general/display_text
$this->scopeConfig->getValue('helloworld/general/enable', MagentoStoreModelScopeInterface::SCOPE_STORE);
$this->scopeConfig->getValue('helloworld/general/display_text', MagentoStoreModelScopeInterface::SCOPE_STORE);
For more information use this link
thank you for your answer. is there a way to display my new configuration fields in my adminpage instead of Store -> Setting -> Configuration ?
– Alexglvr
May 6 '17 at 7:02
you want to create new page that store module configuration details instead of magento default page or you want to just display configuration option tab in your module menu
– Vaibhav Ahalpara
May 6 '17 at 7:06
I need to add several configuration fields for my module, but I would prefer not to add them in Store -> Setting -> Configuration. Therefore I create a menu which is linked to a new admin page. I would like to have my own configuration fields in this new page. I found that : magestore.com/magento-2-tutorial/… but seems to be quite complicated compared to the system.xml solution...
– Alexglvr
May 6 '17 at 7:13
There is 2 way to do this first you have to create form/admin page and save this page data to custome database and second you need to save that data to core_config_data table magento save configuration form data in core_config_data table
– Vaibhav Ahalpara
May 6 '17 at 7:17
I managed to create my configuration form. I now would like a yes/no or check box input field to enable/disable another field. Is it possible?
– Alexglvr
May 9 '17 at 10:06
|
show 2 more comments
The system.xml is a configuration file which is used to create configuration fields in Magento 2 System Configuration.
You will need this if your module has some settings which the admin needs to set. You can go to Store -> Setting -> Configuration to check how it look like.
To Create system.xml
- Step 1: Create System.xml
- Step 2: Set default value
- Step 3: Flush Magento cache
- Step 4: Get value from configuration
app/code/Mageplaza/HelloWorld/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="mageplaza" translate="label" sortOrder="10">
<label>Mageplaza</label>
</tab>
<section id="helloworld" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Hello World</label>
<tab>mageplaza</tab>
<resource>Mageplaza_HelloWorld::hello_configuration</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>General Configuration</label>
<field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Module Enable</label>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
</field>
<field id="display_text" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Display Text</label>
<comment>This text will display on the frontend.</comment>
</field>
</group>
</section>
</system>
</config>
Checking this code, you will see how to create a Tab, Section, Group and Field. We will find more detail about each element:
The Tab element may have many sections and some main attributes and child:
Id attribute is the identify for this tab
sortOrder attribute will define the position of this tab.
Translate attribute let Magento know which title need to translate
Label element child is the text which will show as tab title.
The Section element will have id, sortOrder, translate attributes like the Tab element. Some other attributes (showInDefault, showInWebsite, showInStore) will decide this element will be show on each scope or not. You can change the scope here
The section may have many group and some other child elements:
Class: this value will be added as class for this element. You should you it if you want to make-up this element.
Label: the text title of this element
Tab: this’s a tab id. This tab element will let Magento know the tab which this section is belong to. This section will be placed under that tab
Resource: defined the ACL rule which the admin user must have in order to access this configuration.
Group: This element may have many field and some attributes which is same as Sections.
Fields: is the main path of this page. It will save the data which we want to setting. In this element, we focus on the type attribute. It will define how the element is when display. It can be: text, select, file… In this example we create 2 fields with type select and text. With each type we will define the child element for the field to make it work as we want.
For example, with the type select/multiselect you must define the child element resource_model.
Step 2: Set default value
Each field in system.xml after create will not have any value. When you call them, you will receive ‘null’ result. So for the module, we will need to set the default value for the field and you will call the value without go to config, set value and save it. This default value will be saved in config.xml which is located in etc folder. Let’s create it for this simple configuration:
app/code/Mageplaza/HelloWorld/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>
<hello>
<general>
<enable>1</enable>
<display_text>Hello World</display_text>
</general>
</hello>
</default>
</config>
Note that, if you might get an Error 404 Page Not Found first time, just logout and login again to fix this
Step 3: Flush Magento Cache
https://www.mageplaza.com/kb/how-flush-enable-disable-cache.html
Step 4: Get value from configuration
First all of let’s save value and flush cache, then you can get saved value from database.
In the system.xml, we have added 2 fields: enable and display_text. So the path should be:
helloworld/general/enable
helloworld/general/display_text
$this->scopeConfig->getValue('helloworld/general/enable', MagentoStoreModelScopeInterface::SCOPE_STORE);
$this->scopeConfig->getValue('helloworld/general/display_text', MagentoStoreModelScopeInterface::SCOPE_STORE);
For more information use this link
thank you for your answer. is there a way to display my new configuration fields in my adminpage instead of Store -> Setting -> Configuration ?
– Alexglvr
May 6 '17 at 7:02
you want to create new page that store module configuration details instead of magento default page or you want to just display configuration option tab in your module menu
– Vaibhav Ahalpara
May 6 '17 at 7:06
I need to add several configuration fields for my module, but I would prefer not to add them in Store -> Setting -> Configuration. Therefore I create a menu which is linked to a new admin page. I would like to have my own configuration fields in this new page. I found that : magestore.com/magento-2-tutorial/… but seems to be quite complicated compared to the system.xml solution...
– Alexglvr
May 6 '17 at 7:13
There is 2 way to do this first you have to create form/admin page and save this page data to custome database and second you need to save that data to core_config_data table magento save configuration form data in core_config_data table
– Vaibhav Ahalpara
May 6 '17 at 7:17
I managed to create my configuration form. I now would like a yes/no or check box input field to enable/disable another field. Is it possible?
– Alexglvr
May 9 '17 at 10:06
|
show 2 more comments
The system.xml is a configuration file which is used to create configuration fields in Magento 2 System Configuration.
You will need this if your module has some settings which the admin needs to set. You can go to Store -> Setting -> Configuration to check how it look like.
To Create system.xml
- Step 1: Create System.xml
- Step 2: Set default value
- Step 3: Flush Magento cache
- Step 4: Get value from configuration
app/code/Mageplaza/HelloWorld/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="mageplaza" translate="label" sortOrder="10">
<label>Mageplaza</label>
</tab>
<section id="helloworld" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Hello World</label>
<tab>mageplaza</tab>
<resource>Mageplaza_HelloWorld::hello_configuration</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>General Configuration</label>
<field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Module Enable</label>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
</field>
<field id="display_text" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Display Text</label>
<comment>This text will display on the frontend.</comment>
</field>
</group>
</section>
</system>
</config>
Checking this code, you will see how to create a Tab, Section, Group and Field. We will find more detail about each element:
The Tab element may have many sections and some main attributes and child:
Id attribute is the identify for this tab
sortOrder attribute will define the position of this tab.
Translate attribute let Magento know which title need to translate
Label element child is the text which will show as tab title.
The Section element will have id, sortOrder, translate attributes like the Tab element. Some other attributes (showInDefault, showInWebsite, showInStore) will decide this element will be show on each scope or not. You can change the scope here
The section may have many group and some other child elements:
Class: this value will be added as class for this element. You should you it if you want to make-up this element.
Label: the text title of this element
Tab: this’s a tab id. This tab element will let Magento know the tab which this section is belong to. This section will be placed under that tab
Resource: defined the ACL rule which the admin user must have in order to access this configuration.
Group: This element may have many field and some attributes which is same as Sections.
Fields: is the main path of this page. It will save the data which we want to setting. In this element, we focus on the type attribute. It will define how the element is when display. It can be: text, select, file… In this example we create 2 fields with type select and text. With each type we will define the child element for the field to make it work as we want.
For example, with the type select/multiselect you must define the child element resource_model.
Step 2: Set default value
Each field in system.xml after create will not have any value. When you call them, you will receive ‘null’ result. So for the module, we will need to set the default value for the field and you will call the value without go to config, set value and save it. This default value will be saved in config.xml which is located in etc folder. Let’s create it for this simple configuration:
app/code/Mageplaza/HelloWorld/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>
<hello>
<general>
<enable>1</enable>
<display_text>Hello World</display_text>
</general>
</hello>
</default>
</config>
Note that, if you might get an Error 404 Page Not Found first time, just logout and login again to fix this
Step 3: Flush Magento Cache
https://www.mageplaza.com/kb/how-flush-enable-disable-cache.html
Step 4: Get value from configuration
First all of let’s save value and flush cache, then you can get saved value from database.
In the system.xml, we have added 2 fields: enable and display_text. So the path should be:
helloworld/general/enable
helloworld/general/display_text
$this->scopeConfig->getValue('helloworld/general/enable', MagentoStoreModelScopeInterface::SCOPE_STORE);
$this->scopeConfig->getValue('helloworld/general/display_text', MagentoStoreModelScopeInterface::SCOPE_STORE);
For more information use this link
The system.xml is a configuration file which is used to create configuration fields in Magento 2 System Configuration.
You will need this if your module has some settings which the admin needs to set. You can go to Store -> Setting -> Configuration to check how it look like.
To Create system.xml
- Step 1: Create System.xml
- Step 2: Set default value
- Step 3: Flush Magento cache
- Step 4: Get value from configuration
app/code/Mageplaza/HelloWorld/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="mageplaza" translate="label" sortOrder="10">
<label>Mageplaza</label>
</tab>
<section id="helloworld" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Hello World</label>
<tab>mageplaza</tab>
<resource>Mageplaza_HelloWorld::hello_configuration</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>General Configuration</label>
<field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Module Enable</label>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
</field>
<field id="display_text" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Display Text</label>
<comment>This text will display on the frontend.</comment>
</field>
</group>
</section>
</system>
</config>
Checking this code, you will see how to create a Tab, Section, Group and Field. We will find more detail about each element:
The Tab element may have many sections and some main attributes and child:
Id attribute is the identify for this tab
sortOrder attribute will define the position of this tab.
Translate attribute let Magento know which title need to translate
Label element child is the text which will show as tab title.
The Section element will have id, sortOrder, translate attributes like the Tab element. Some other attributes (showInDefault, showInWebsite, showInStore) will decide this element will be show on each scope or not. You can change the scope here
The section may have many group and some other child elements:
Class: this value will be added as class for this element. You should you it if you want to make-up this element.
Label: the text title of this element
Tab: this’s a tab id. This tab element will let Magento know the tab which this section is belong to. This section will be placed under that tab
Resource: defined the ACL rule which the admin user must have in order to access this configuration.
Group: This element may have many field and some attributes which is same as Sections.
Fields: is the main path of this page. It will save the data which we want to setting. In this element, we focus on the type attribute. It will define how the element is when display. It can be: text, select, file… In this example we create 2 fields with type select and text. With each type we will define the child element for the field to make it work as we want.
For example, with the type select/multiselect you must define the child element resource_model.
Step 2: Set default value
Each field in system.xml after create will not have any value. When you call them, you will receive ‘null’ result. So for the module, we will need to set the default value for the field and you will call the value without go to config, set value and save it. This default value will be saved in config.xml which is located in etc folder. Let’s create it for this simple configuration:
app/code/Mageplaza/HelloWorld/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>
<hello>
<general>
<enable>1</enable>
<display_text>Hello World</display_text>
</general>
</hello>
</default>
</config>
Note that, if you might get an Error 404 Page Not Found first time, just logout and login again to fix this
Step 3: Flush Magento Cache
https://www.mageplaza.com/kb/how-flush-enable-disable-cache.html
Step 4: Get value from configuration
First all of let’s save value and flush cache, then you can get saved value from database.
In the system.xml, we have added 2 fields: enable and display_text. So the path should be:
helloworld/general/enable
helloworld/general/display_text
$this->scopeConfig->getValue('helloworld/general/enable', MagentoStoreModelScopeInterface::SCOPE_STORE);
$this->scopeConfig->getValue('helloworld/general/display_text', MagentoStoreModelScopeInterface::SCOPE_STORE);
For more information use this link
edited Oct 12 '17 at 4:40
Rohan Hapani
1
1
answered May 6 '17 at 7:00
Vaibhav AhalparaVaibhav Ahalpara
3,68542762
3,68542762
thank you for your answer. is there a way to display my new configuration fields in my adminpage instead of Store -> Setting -> Configuration ?
– Alexglvr
May 6 '17 at 7:02
you want to create new page that store module configuration details instead of magento default page or you want to just display configuration option tab in your module menu
– Vaibhav Ahalpara
May 6 '17 at 7:06
I need to add several configuration fields for my module, but I would prefer not to add them in Store -> Setting -> Configuration. Therefore I create a menu which is linked to a new admin page. I would like to have my own configuration fields in this new page. I found that : magestore.com/magento-2-tutorial/… but seems to be quite complicated compared to the system.xml solution...
– Alexglvr
May 6 '17 at 7:13
There is 2 way to do this first you have to create form/admin page and save this page data to custome database and second you need to save that data to core_config_data table magento save configuration form data in core_config_data table
– Vaibhav Ahalpara
May 6 '17 at 7:17
I managed to create my configuration form. I now would like a yes/no or check box input field to enable/disable another field. Is it possible?
– Alexglvr
May 9 '17 at 10:06
|
show 2 more comments
thank you for your answer. is there a way to display my new configuration fields in my adminpage instead of Store -> Setting -> Configuration ?
– Alexglvr
May 6 '17 at 7:02
you want to create new page that store module configuration details instead of magento default page or you want to just display configuration option tab in your module menu
– Vaibhav Ahalpara
May 6 '17 at 7:06
I need to add several configuration fields for my module, but I would prefer not to add them in Store -> Setting -> Configuration. Therefore I create a menu which is linked to a new admin page. I would like to have my own configuration fields in this new page. I found that : magestore.com/magento-2-tutorial/… but seems to be quite complicated compared to the system.xml solution...
– Alexglvr
May 6 '17 at 7:13
There is 2 way to do this first you have to create form/admin page and save this page data to custome database and second you need to save that data to core_config_data table magento save configuration form data in core_config_data table
– Vaibhav Ahalpara
May 6 '17 at 7:17
I managed to create my configuration form. I now would like a yes/no or check box input field to enable/disable another field. Is it possible?
– Alexglvr
May 9 '17 at 10:06
thank you for your answer. is there a way to display my new configuration fields in my adminpage instead of Store -> Setting -> Configuration ?
– Alexglvr
May 6 '17 at 7:02
thank you for your answer. is there a way to display my new configuration fields in my adminpage instead of Store -> Setting -> Configuration ?
– Alexglvr
May 6 '17 at 7:02
you want to create new page that store module configuration details instead of magento default page or you want to just display configuration option tab in your module menu
– Vaibhav Ahalpara
May 6 '17 at 7:06
you want to create new page that store module configuration details instead of magento default page or you want to just display configuration option tab in your module menu
– Vaibhav Ahalpara
May 6 '17 at 7:06
I need to add several configuration fields for my module, but I would prefer not to add them in Store -> Setting -> Configuration. Therefore I create a menu which is linked to a new admin page. I would like to have my own configuration fields in this new page. I found that : magestore.com/magento-2-tutorial/… but seems to be quite complicated compared to the system.xml solution...
– Alexglvr
May 6 '17 at 7:13
I need to add several configuration fields for my module, but I would prefer not to add them in Store -> Setting -> Configuration. Therefore I create a menu which is linked to a new admin page. I would like to have my own configuration fields in this new page. I found that : magestore.com/magento-2-tutorial/… but seems to be quite complicated compared to the system.xml solution...
– Alexglvr
May 6 '17 at 7:13
There is 2 way to do this first you have to create form/admin page and save this page data to custome database and second you need to save that data to core_config_data table magento save configuration form data in core_config_data table
– Vaibhav Ahalpara
May 6 '17 at 7:17
There is 2 way to do this first you have to create form/admin page and save this page data to custome database and second you need to save that data to core_config_data table magento save configuration form data in core_config_data table
– Vaibhav Ahalpara
May 6 '17 at 7:17
I managed to create my configuration form. I now would like a yes/no or check box input field to enable/disable another field. Is it possible?
– Alexglvr
May 9 '17 at 10:06
I managed to create my configuration form. I now would like a yes/no or check box input field to enable/disable another field. Is it possible?
– Alexglvr
May 9 '17 at 10:06
|
show 2 more comments
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f173286%2fmagento2-how-to-create-admin-page-with-configuration-fields%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
For configuration, should use
core_config_data
table.– Khoa TruongDinh
May 6 '17 at 6:49