Adminhtml settings

 

 

Magento configuration. The Magento system configuration page is logically divided into several parts: tabs, sections, groups and fields. Let's create simple configuration. We will create a new tab, new section and a group.Let's open our new module.TestVendorName/TestModuleName.system dot xml file should located in e t c adminhtml folder, so let's create itAnd let's get an example of this file from our magento/module-cataloge t c admin html system dot xmlSo let's keep only one tab, one section, and one group.And let's delete all this unnecessary data.So we have a tab, section and group with some fields.The ID attribute is the ID of this tab. Let's change it to test_tab_id.The Translate attribute lets Magento know which title you need to translate. The sort order attribute will determine position of this tab, so let's change it to 1.The label is the text that will appear as the tab title. So let's change it to "Test Tab Name".Great.The section element will have an ID, sort order, and translation attributes as in the tab element.And also some other attributes like "showInDefault", "showInWebsite", "showInStore" which will determine whether this element will be shown in every area or not. Here you can change the scope.So let's change sortOrder to 10 and change the section ID.this could be test section id.Great!A section can have many groups and some other children.For example, class. This value will be added as a class for this HTML element.So let's leave everything as it is.Label. The text title of this element. So let's change it to Test Section LabelAnd the name of the tab, test tab id.And Resource defined the access control list rule, which the admin user must have in order to access this configuration.This way you can protect this configuration from some admin user groups.Let's change The module name to TestVendorName TestModuleNameAnd the name of this resource. Something like test_resource_idAnd group! this element can have many fields and some attributes same as sections, so let's change group id to something like test group id let's change the sort order and leave the scope values ​​as is, and of course change the group label for some, like Test Group LabelAnd finally, the fields. In the fields we can define the type of this element.It will determine how the element will look when rendered.This could be a text or file selection.So we're going to use the text type for testing purposes.Let's keep only two fields.Let's say test_field_Id1and test_field_id2And let's leave Translate, type as is.We can change sortOrder and showInWebsite to 1 and showInStore to 1.And canRestore to 1. canRestore actually means you can restore the default values. So you can change it in the admin panel and save it to the database, but then you can restore those defaults.This can be really helpful.So let's leave it at 1.And let's add some test comments.And let's change Test Field Label2 and Test Field Label1.We have test_tab_id in this test_tab_id, we have test_section_id and we mentioned that here we need to use test_tab_id.Inside test_section_id we have test_group_id with just two fieldstest_field_id1 and test_field_id2Both are text values.And now we can see this in the admin panel.Also we need to clear the cache because every time we change the configuration or something in the .xml files we have to clear the cache.Let's move on to Stores ConfigurationWe can see the Test tab title, test section label, and test group label, which is great.See that we don't have any predefined value. That's because we didn't set it.For this we need the e t c config dot xml file.Here we can specify all the default values ​​for our configuration. For this we can get an example from our magento/module-catalog folder.Let's take the config dot xml file from here and copy it here.We will delete all unnecessary data.As you can see, the structure is quite simple.We need to specify the section ID, then the group ID, and the field ID. So let's do this.Let's get our section ID here.Let's get group ID here.And let's get field id here.Let's set some default value.Test Default ValueAnd now we can see the changes in the admin panel.As you remember, we have to clear the cache.Let's go to Stores -> ConfigurationAs you can see, we have some default value.Now we will be able to change it and then restore the default settings.Let's change the value hereTest Another ValueNow we need to save it.And we can take a look at our database.So every time you save something in the admin panel, those values ​​will be saved in the "core config data" table.Let's try to find our "test section id", "test group id" and "test field id" valueSo, as you can see, we have "Test Another Value".So now if you have some value in the database you will get that value instead of the default value from config dot xml fileThe value in the database has a higher priority than the value in the .xml file.That's all. This is how configuration works in Magento.
You have completed 0% of the lesson
0%