When you are creating a new module , but the requirement is for setting some configuration for magento 2 backend then you need a file which will describe the Magento 2 backend system configuration of our module that is system.xml file. Get the the tricks to create configuration field in magento 2 back-end System configuration field.

Magento-2-backend-system-configuration
Magento-2-backend-system-configuration

Magento 2 backend system configuration

Magento 2 backend system configuration option values are store in core_config_data table.

Generally magento 2 configuration divided into four parts as like as magento 1 How to create custom configuration fields for magento

Tab => Section => Group => Filed.

I have used VendorName_ComponentName as JRB_Customconfig. So VendorName: JRB and ComponentName: Customconfig

Magento 2 backend system-configuration
Magento 2 backend system-configuration

If we are creating our own custom section then we need to give permission to our section in admin by declaring ACL.

then after we can add our custom section in backend:

Tab:

Attributes used :

  • translate : it is used to translate the label text that is used for tab rendering.
  • sort_order : It describe the tab position with other tabs.
  • id : it is unique name to identify tab of configuration

Used Nodes:

  • label: it is the label text that is used for tab rendering.
  • section: contains the description of section that will be shown below.

Section :

Attributes used :

  • translate : it is used to translate the label text that is used for section rendering.
  • sort_order : It describe the tab position with other section.
  • id : it is unique name to identify section of configuration under a specific tab
  • showInDefault: means this section will be shown when default value is selected in current configuration scope.
  • showInWebsite: means this section will be shown when a website is selected in current configuration scope.
  • showInStore: means this section will be shown store is selected in current configuration scope.

Used Nodes:

  • label: it is the label text that is used for section rendering.
  • tab: it is used to define the tab name under which this section will belongs.
  • resource: the defined resource name will be used to ACL through which we can give permission to our custom section
  • group: contains the description of group that will be shown below.

Group:

Attributes used :

  • translate : it is used to translate the label text that is used for group rendering.
  • sort_order : It describe the tab position with other group.
  • id : it is unique name to identify group of configuration under specific section
  • showInDefault: means this section will be shown when default value is selected in current configuration scope.
  • showInWebsite: means this section will be shown when a website is selected in current configuration scope.

Used Nodes:

  • label: it is the label text that is used for group rendering.
  • field: contains the description of field that will be shown below.

Field:

Attributes used :

  • type: type of field
  • translate : it is used to translate the label text that is used for field rendering.
  • sort_order : It describe the tab position with other tabs.
  • id : it is unique name to identify field of configuration under specific group
  • showInDefault: means this section will be shown when deafult value is selected in current configuration scope.
  • showInWebsite: means this section will be shown when a website is selected in current configuration scope.
  • showInStore: means this section will be shown store is selected in current configuration scope.

Used Nodes:

  • label: it is the label text that is used for field rendering.
  • comment: contains the description of field. validate: validate input filed of that form

Magento 2 backend system configuration provides below fields type:

  • checkbox,
  • checkboxes,
  • column,
  • date,
  • editablemultiselect,
  • editor,
  • fieldset,
  • file,
  • gallery,
  • hidden,
  • image,
  • imagefile,
  • label,
  • link,
  • multiline,
  • multiselect,
  • note,
  • obscure,
  • password,
  • radio,
  • radios,
  • reset,
  • select,
  • submit,
  • text,
  • textarea,
  • time

List of mostly used source models:

  • Magento\Config\Model\Config\Source\Admin\Page – returns list of all the items in Magento Admin menu
  • Magento\Config\Model\Config\Source\Date\Short – returns list of available short date formats
  • Magento\Config\Model\Config\Source\Email\Identity – returns list of email sending identities (General Contact, Sales Representative, etc)
  • Magento\Config\Model\Config\Source\Email\Template – returns list of transactional email templates
  • Magento\Config\Model\Config\Source\Email\Method – returns list of transactional email methods (Bcc,Separate Email)
  • Magento\Config\Model\Config\Source\Email\Smtpauth\Smtpauth – returns list of SMTP Authorization (NONE,PLAIN,LOGIN,CRAM-MD5)
  • Magento\Config\Model\Config\Source\Locale\Country – returns list of localized country names
  • Magento\Config\Model\Config\Source\Locale\Currency\All – returns list of all currency names
  • Magento\Config\Model\Config\Source\Locale\Currency – returns list of localized currency names
  • Magento\Config\Model\Config\Source\Locale\Timezone – returns list of localized timezone names
  • Magento\Config\Model\Config\Source\Locale\Weekdays – returns list of localized weekday names
  • Magento\Config\Model\Config\Source\Locale\Weekdaycodes – returns list of localized weekday codes
  • Magento\Config\Model\Config\Source\Image\Adapter – returns hash of image adapter codes and labels
  • Magento\Config\Model\Config\Source\Reports\Scope – returns scope filter(Website,Store,Store View)
  • Magento\Config\Model\Config\Source\Design\Robots – returns all roboto txt contents(‘INDEX, FOLLOW’,’NOINDEX, FOLLOW’,’INDEX, NOFOLLOW’,’NOINDEX, NOFOLLOW’)
  • Magento\Config\Model\Config\Source\Dev\Dbautoup – returns auto update texts (‘Always (during development)’,’Only Once (version upgrade)’,’Never (production)’)
  • Magento\Config\Model\Config\Source\Web\Protocol – returns http/https of URL(‘HTTP (unsecure)’,’HTTPS (SSL)’)
  • Magento\Config\Model\Config\Source\Web\Redirect – returns URL redirect types(‘No’,’Yes (302 Found)’,’Yes (301 Moved Permanently)’)
  • Magento\Config\Model\Config\Source\Website\OptionHash – returns websites array
  • Magento\Config\Model\Config\Source\Enabledisable – return list of two options (“Enable” and “Disable”)
  • Magento\Config\Model\Config\Source\Nooptreq – return list of three options for customer widget mandatory indetificator (“Not”, “Optional”, “Required”).
  • Magento\Config\Model\Config\Source\Locale – return list of all locale
  • Magento\Config\Model\Config\Source\Yesno – return boolean options (“Yes”, “No”)
  • Magento\Config\Model\Config\Source\Website – return list of available websites
  • Magento\Config\Model\Config\Source\Store – return list of available stores

Apart from above source model we can create our own source module by implementing \Magento\Framework\Option\ArrayInterface
File location: app/code/JRB/Customconfig/Model/Config/Source/Ownsource.php

above source model can be called through system.xml file.
File location: app/code/JRB/Customconfig/etc/adminhtml/system.xml

some of concepts needs to know:

Depends field :

Grouping groups:

Image Upload:

Most of available source models : Magento\Config\Model\Config\Source\*
Most of available backend models : Magento\Config\Model\Config\Backend\*
Most of available validation classes : lib/web/mage/validation.js

 

Thanks for visiting this article, hope you understand this article (‘Magento 2 backend system configuration’).

 

Magento 2 backend system configuration
Tagged on:                     

Leave a Reply

Your email address will not be published.