I'd like to create my custom field type to use it in system config forms (System -> Configuration). For example, to create simple text field we need to use <frontend_type>text</frontend_type>
in system.xml which tells Magento to use file lib/Varien/Data/Form/Element/Text.php
:
<config>
<!-- ... -->
<sections>
<mycustom_section translate="label">
<label>My Module</label>
<sort_order>0</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<mycustom_group translate="label">
<label>My Custom Group</label>
<sort_order>0</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<heading_sample translate="label">
<label>Sample heading</label>
<sort_order>0</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
</heading_sample>
<mycustom_field translate="label comment">
<label>My Custom Field</label>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<frontend_type>text</frontend_type> <!-- custom field type here -->
<frontend_model>mymodule/custom</frontend_model> <!-- or custom model here -->
</mycustom_field>
<!-- ...other fields here... -->
</fields>
</mycustom_group>
</groups>
</mycustom_section>
</sections>
</config>
If I create my own class (that extends Magento's Varien_Data_Form_Element_Abstract
class) that renders my custom field, where I should put this file?
It will probably work (will it?) if I put it inside Magento default directory
lib/Varien/Data/Form/Element/Customized.php
:
<mycustom_group>
<!-- ... -->
<fields>
<mycustom_field translate="label comment">
<label>My Custom Field</label>
<comment>Some comment about my field</comment>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<frontend_type>customized</frontend_type> <!-- custom field type here -->
</mycustom_field>
</fields>
</mycustom_group>
But is there any way to keep my custom field file inside my custom module instead in
lib/Varien/Data/Form/Element/
? Adding custom files to the core directories isn't probably very good idea.If not, can I create custom folder inside
lib/
, for example:lib/Mycompany/Customized.php
? But in that case, how I can inform Magento in the<frontend_type>
tag inside system.xml that it should use my custom field file and tell Magento where that file is located?
System -> Configuration -> My Module
. I will add simple text fields, simple drop-down lists but also I need to add there some custom extended fields for which Magento doesn't have any default form fields (so I need to build my own).yourcompany/customized
for thefrontend_type
?<frontend_type>yourcompany/customized</frontend_type>
in system.xml, then where I should put my file? This is the part which I don't understand. :)