2
votes

Instead of using the system.xml to create groups and sections in a static way I want to create a section and groups in the code. Pls take a look at the screenshot:

groups

Whats shown on the screen was done in the modules system.xml, now I want to do that directly in the code. I also found the place where the form is being built, its in app/code/core/Mage/Adminhtml/Block/System/Config/Form.php in the initForm() function. There it reads the sections and the inner groups. The problem I have is, that I dont know how to proceed from here. Maybe somebody has done a similiar thing or can point me in the right direction. I guess part of it is creating a Mage_Core_Model_Config_Element by myself?

1

1 Answers

6
votes

This way to use system/config screen is not the Magento standard.

If you want to keep stay in standard, you have two options:

  1. Create your own config screen.
  2. Use the frontend_model property of groups in your config.xml

    <?xml version="1.0"?>
    <config>
        <sections>
            <your_section>
                <groups>
                    <your_group>
                         <frontend_model>your_module/your_block</frontend_model>
                    </your_group>
                </groups>
            </your_section>
        </sections>
    </config>
    

Then you are able to do whatever you want with the provided block, create dynamically as many fieldset as you want, adding custom fields, etc.

This block must extends Mage_Adminhtml_Block_System_Config_Form_Fieldset and if you want your fields to save data in core_config_data, they will need to have name='groups[your_group][fields][your_field][value]' (Magento will take care of the your_section part for you).

Your fields must read data theimselves too, just put that in their value attribute.