Get Free Audit

How to Configure Magento 2 Custom System

Sep 4, 2018

6436 Andrey Litvin

How to Configure Magento 2 Custom System

Magento 2 allows you to extend the system configuration using modules. This will allow you to integrate the configuration of your module into the Magento 2 system menu.

Adding such custom settings is done using the app/code/Vendor/Module/etc/adminhtml/system.xml file


And now in parts:


This xml code allows you to add a new tab to the settings menu of Magento 2.

Adding a new tab to the settings menu of Magento 2.

Next:


This code adds a new section and assigns it to the custom_tab tab. Here can be used any tab from existing ones.

The parameters showInDefault = “1”, showInWebsite = “1” and showInStore = “1” indicate the scope in which our section will be visible.

This code adds a new section and assigns it to the custom_tab tab. Any tab from existing ones can be used here.

The parameters showInDefault = “1”, showInWebsite = “1” and showInStore = “1” indicate the scope in which our section will be visible.

Elements

Simple Text Field

Yes/No Dropdown

Andrey_Dubina
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey

Dropdown With The Custom Source model


And our custom model can look like this: app/code/Vendor/Module/Model/Config/Source/Custom.php

File Upload


<validate>validate-no-empty</validate> checks to ensure that the field is not empty when saving the configuration.

Depends tag allows you to show this field only when yesno_dropdown is set to “Yes”.

Textarea

Secret Field


type=”obscure” hides the field value from the frontend, but in this case, the data will still be stored as plain text.

Setting Magento\Config\Model\Config\Backend\Encrypted as a backend model allows you to encrypt the data in the database.

Most of the source models are located in app/code/Magento/Config/Model/Config/Source and backend models are located in app/code/Magento/Config/Model/Config/Backend.

Setting Default Value

To set the default value for any of our custom settings, you need to create the app/code/Vendor/Module/etc/config.xml file

Getting Values

We will use Helper Class to get the values from our configuration: app/code/Vendor/Module/Helper/Data.php


This method receives a string representing the path to the required option in the form of section/group/field. That means that to get the value of custom_text field, we need to pass the string custom_section/general/custom_text.

Need a ready-made and quality Magento solution? Visit BelVG store and find the one you needed.

dropdown_menu_1_1

Dropdown Menu

Take your store to the new level with BelVG extension

Download here
Andrey Dubina
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Andrey

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *