Patching/rewrite files in lib/Varien
-
11-12-2019 - |
Question
I would like to know people's thoughts on the best way to patch/rewrite Varien lib files. Specifically whey looking into a couple of issues one with checkboxes and one with image type inputs I found that both these Varien elements have what I would deem as bugs.
So my What is the upgrade safe way of updating the following files?
Varien_Data_Form_Element_Image
Varien_Data_Form_Element_Checkboxes
Solution
Unfortunately there is no way to override these classes.
What you can do is treat them as abstract core classes.
Copy them to the local
folder and make your changes there.
There is also the long and painful option of creating your own classes and changing the code that uses them to use your classes.
But that may end badly. It may not even be possible.
OTHER TIPS
So if you are making your own form, or rewriting a current form and your class extends Mage_Adminhtml_Block_Widget_Form
then you can use the function _getAdditionalElementTypes
to specify which form types use which class to render.
With this function you could override what standard form elements are used and also define your own if that was what you needed.
A great example of this can be found in the customer module in the class Mage_Adminhtml_Block_Customer_Edit_Tab_Account
. Here you can find that the classes for image, file and boolean are form elements are set.
/**
* Return predefined additional element types
*
* @return array
*/
protected function _getAdditionalElementTypes()
{
return array(
'file' => Mage::getConfig()->getBlockClassName('adminhtml/customer_form_element_file'),
'image' => Mage::getConfig()->getBlockClassName('adminhtml/customer_form_element_image'),
'boolean' => Mage::getConfig()->getBlockClassName('adminhtml/customer_form_element_boolean'),
);
}
If you then look into these form elements you can see examples of changing the the code to match your own needs.