Adding a Custom Form Element to an Adminhtml Form

后端 未结 3 1554
[愿得一人]
[愿得一人] 2021-02-02 16:00

Is there a way to add a custom form element to a Magento Adminhtml form without placing the custom element in the lib/Varian folder?

I\'ve tracked down the

3条回答
  •  难免孤独
    2021-02-02 16:53

    The class Varien_Data_Form_Abstract has a method addType() where you can add new element types and their respective class names. To exploit this functionality you can copy the block Mage_Adminhtml_Block_Widget_Form to the local code pool and extend the method _getAdditionalElementTypes():

    protected function _getAdditionalElementTypes()
    {
        $types = array(
            'my_type' => 'Namespace_MyModule_Block_Widget_Form_Element_MyType',
        );
    
        return $types;
    }
    

    As the class Mage_Adminhtml_Block_Widget_Form is a base class for all the other form classes, unfortunately just rewriting the block in the config will not work.

    EDIT: If you need the custom element types in just one form you could override the specific class and add the type there by overriding the method _getAdditionelElementTypes(). This would be a cleaner solution than copying an importend magento class to the local code pool.

    EDIT2: Looking at Mage_Adminhtml_Block_Widget_Form::_setFieldset() there is another possibility: If the attribute has a value in frontend_input_renderer (e.g. mymodule/element_mytype) then a block with that name is loaded. See also Mage/Eav/Model/Entity/Attribute/Frontend/Abstract.php line 160. This should work without overriding any Magento classes.

提交回复
热议问题