At the time of creating a new module if our requirement is for setting some configuration for magento backend then we need a file which will describe the configuration of our module that is system.xml file.Get the the tricks to create configuration field in magento back-end System configuration field.

So it generally gives more flexibility for admin user who can set all setting easily in magento admin.For this magento gives you ability to create sections under section => configuration.In this article I will show you How to create custom configuration fields for magento.

How to create custom configuration fields for magento
custom configuration fields

Generally magento configuration divided into four parts that is

Tabs => Sections => Groups => Fileds.

That means Tabs contain Sections ,Sections contain Groups,Groups contain Fields.So all these declarations can defined in system.xml file in etc folder of any module e.g. :

App/Code/Local or community/NameSpace/ModuleName/etc/system.xml

[crayon-5dcd2bb755137242272383/]
After declaring all section tabs and field it needs to inform and get permission from for your section to approve in magento backend.For that you declare in acl of magento that can be place in config.xml file or adminhtml.xml file.Here I have all in acl of magento so have a look below file.
[crayon-5dcd2bb755140887932301/]
So this was the all about How to create custom configuration for magento backend but there needs to clear all about secion how they wroks and where is there functionality will be and what each node mean.lets see one by one.

Tabs:

[crayon-5dcd2bb755145523312797/]

How to create custom configuration fields for magento
custom configuration fields

Here the node_name(that is my_custom_tab in above case ) is the unique identifier of tab and the module attribute is used to specify which module will be used for translation translate tab is used for which node to translate.

These nodes generally contains children like :
  • label : it is the label text that is used for tab rendering.
  • sort_order : It describe the tab position with other tabs.
  • class : its the css class that used for tab.

Sections :

[crayon-5dcd2bb75514a598657614/]
Here the node_name(that is my_custom_section in above case ) is the unique identifier of section and the module attribute is used to specify which module will be used for translation translate tab is used for which node to translate.

These nodes generally contains children like :
  • label : it is the label text that shown under tabs and on the right side as page heading.
  • sort_order : It describe the position inside the tab with other sections.
  • class : its the css class that used for tabs block.
  • header_css:CSS class used on section edit form (that will be use in after clicking on section label)
  • use_in_default :means this section will be shown when deafult value is selected in current configuration scope.
  • use_in_website: means this section will be shown when a website is selected in current configuration scope.
  • use_in_store: means this section will be shown store is selected in current configuration scope.
  • frontend_model: this is calss that is used to render form.(Default is adminhtml/system_config_form)
  • groups: contains the description of group that will be shown below.

Groups:

[crayon-5dcd2bb75514e919049267/]
Here the node_name(that is my_custom_group in above case ) is the unique identifier of custom section and the module attribute is used to specify which module will be used for translation translate tab is used for which node to translate.

These nodes generally contains children like :
  • label : it is the label text that shown under tabs and on the right side as page heading.
  • sort_order : It describe the position inside the tab with other sections.
  • use_in_default : means this section will be shown when deafult value is selected in current configuration scope.
  • use_in_website: means this section will be shown when a website is selected in current configuration scope.
  • use_in_store: means this section will be shown store is selected in current configuration scope.
  • frontend_model: this is calss that is used to render fieldset.(Default is adminhtml/system_config_form_fieldset)
  • comment: it contain some notice about configuration group or whatever you want.
  • expanded : it will allow group to toggle to admin by default groups are in expanded mode.
  • sort_fields : sorting order inside group.it may contain following children:
  • by : it is the child node name of the field node for which will be used as sort value
  • direction_desc : if it is 1 the sorting will be on reverse order.
  • clone_fields and clone_model: these are use to create configuration field duplicates with some prefixes.

clone_fields is a boolean and clone_model is the contains the model class that should be used for retrieving the prefixes.The model should contain getPrefixes() methods that will return an array of an assocateive array that will contain all fields and label.e.g:
[crayon-5dcd2bb755153337413248/]
fields: contains the description of groups.

Fields:

[crayon-5dcd2bb755157234578728/]

Here the node_name(that is my_custom_field in above case ) is the unique identifier of custom section and the module attribute is used to specify which module will be used for translation translate tab is used for which node to translate.

These nodes generally contains children like :
  • label : it is the label text that shown under tabs and on the right side as page heading.
  • sort_order : It describe the position inside the tab with other sections.
  • config_path: Identify which configuration field should be saved.If not specified the configuration field path will be used([section_name]/[group_name]/[field_name]).e.g: field value will be saved in my_custom_section/my_custom_group/my_custom_field.
  • frontend_model: this is calss that is used to render field.(Default is adminhtml/system_config_form_field)
  • frontend_type : this is the field input type for form items.aome possible types are :
  • text: Text input field
  • textarea : Textarea field
  • select : Dropdown field. Options for this field are retrieved from source_model
  • multiselect : Multiselect field. Options for this field are retrieved from source_model
  • import : File input field for importing of the data
  • export : File export button that is used for exporting of the data
  • allowspecific : Dropdown field that displays “Allow Specific Countries” and “All Countries” as its options
  • image : File input field for uploading of an image and all the fields presented as Varien_Data_Form_Element_* …If value is not specified, text input type will be used.
  • can_be_empty : indicates that multiselect field can contain no values selected, otherwise empty selection will not be saved
  • source_model : specifies source model that returns option list for select and multiselect fields types. Value contains model class name or model callback. If you specify only class name your module should implement toOptionArray($isMultiselect) method, that will return a list of prepared option array for form element. If you specify model callback, your source model should just return only associative array of value-label pairs. Example of model callback: module_name/model_name::methodName

List of mostly used source models:

  • adminhtml/system_config_source_admin_page – returns list of all the items in Magento Admin menu
  • adminhtml/system_config_source_cms_page – returns list of CMS Pages
  • adminhtml/system_config_source_customer_group – returns list of customer groups
  • adminhtml/system_config_source_date_short – returns list of available short date formats
  • adminhtml/system_config_source_email_identity – returns list of email sending identities (General Contact, Sales Representative, etc)
  • adminhtml/system_config_source_email_template – returns list of transactional email templates
  • adminhtml/system_config_source_locale_country – returns list of localized country names
  • adminhtml/system_config_source_locale_currency – returns list of localized currency names
  • adminhtml/system_config_source_locale_timezone – returns list of localized timezone names
  • adminhtml/system_config_source_locale_weekdays – returns list of localized weekday names
  • adminhtml/system_config_source_order_status – returns list of available order statuses except pending payment
  • adminhtml/system_config_source_payment_allmethods – returns list of all payment methods
  • adminhtml/system_config_source_shipping_allmethods – returns list of all shipping methods
  • adminhtml/system_config_source_country – returns list of all countries from directory module
  • adminhtml/system_config_source_allregion – returns list of all country regions grouped by country
  • adminhtml/system_config_source_enabledisable – return list of two options (“Enable” and “Disable”)
  • adminhtml/system_config_source_notoptreq – return list of three options for customer widget mandatory indetificator (“Not”, “Optional”, “Required”).
  • adminhtml/system_config_source_yesno – return boolean options (“Yes”, “No”)

You can find more available source models at Mage_Adminhtml_Model_System_Config_Source_*

  • backend_model : specifies custom model for saving of configration value data. If you want to implement such custom logic, you should extend your backend model from Mage_Core_Model_Config_Data
  • use_in_default : indicates that this field will be showed when “Default Values” is selected in “Current Configuration Scope”
  • use_in_website : indicates that this field will be showed when a website is selected in “Current Configuration Scope”
  • use_in_store : indicates that this field will be showed when a store view is selected in “Current Configuration Scope”
  • tooltip : tooltip text for field. This text is displayed when the mouse is over the field. If you want to specify custom html block for text in tooltip, you should use tooltip_block
  • tooltip_block : block class name that will be used as tooltip for this field instead of tooltip text
  • validate : CSS class name that will be applied to form field. Used for validation of the field input. Some usual values:
  • required-entry : validates field value as non empty
  • validate-number : validates field value as numeric
  • validate-email : validates field value as valid email address.All the possible validation rules can be found at js/prototype/validation.js
  • comment : text that will be displayed before all the items in form, may contain some notice about field value format group or whatever you want. Also this field can use a comment generator model. In these case you need specify the following children for it:
  • model : model class name that should implement getCommentTextmethod with public access. Parameters those are passed to this method are the following:
  • $element : configuration node itself
  • $currentValue : current field value
  • depends : this node contains list of dependencies of the current field to other fields. The structure of this node is very simple. The child node name is name of field on what this one depends, and the node value is value for make this field visible.
For example such configuration:

[crayon-5dcd2bb75515e572858292/]
will add rule for displaying of the current field only if the value of field called “field_name” equals to 1.

Hope you enjoyed the post with me.So please don’t be selfish ,If got benefit then please share this post with others.

How to create custom configuration fields for magento
The following two tabs change content below.
Jyotiranjan is one of passionate programmer who has been working in magento since 6 years and in the mean time he has developed enormous amount of modules and customisation of sites. He loves to write blogs and travel for long journeying.

Latest posts by Jyotiranjan Biswal (see all)

Tagged on:                     

Leave a Reply

Your email address will not be published. Required fields are marked *