Monday, July 16, 2012

Mage_Adminhtml_Block_Widget_Form

Mage_Adminhtml_Block_Widget_Form class is never instantiated.
It is only extended by other classes.
This is never called inside Magento ‘new Mage_Adminhtml_Block_Widget_Form()’.
So even if you override the class all the other classes that extend Mage_Adminhtml_Block_Widget_Form will still extend the original one and not your class.
You are not adding an other level in the inheritance tree. You just add and other sibling to the classes that extend Mage_Adminhtml_Block_Widget_Form.

You have 2 solutions here.
1. Quick and dirty - copy the Mage_Adminhtml_Block_Widget_Form class file in the app/code/local folder (following all the required paths) and edit it in there. When Magento looks for a class first searches in the app/code/local folder then in app/code/community and in the end in app/code/local. This means that all the classes that extend Mage_Adminhtml_Block_Widget_Form will extend your class instead (because this is the first one found by Magento).

2. Clean but very time consuming method (that might turn out to be useless in the end) - Create a class that extends Mage_Adminhtml_Block_Widget_Form (just like you did) and override all the classes that extend Mage_Adminhtml_Block_Widget_Form and make them extend your class. This is a good practice if you have a small number of classes in this case (for example it could work for Mage_Customer_Model_Address_Abstract) but in your case there are a lot of these classes. It will take a lot of time and might be hard to manage in the end.

So you can use first solution.  There is a risk that on a future upgrade you will loose some functionality (but the chance is slim). You might loose more (time and functionality with the second one).

No comments:

Post a Comment