2

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?

  1. Varien_Data_Form_Element_Image
  2. Varien_Data_Form_Element_Checkboxes
  • are lid/Varien files acutally updated when an update is released? – Julien Lachal Jul 25 '14 at 14:37
  • good question, technically they could be. Not sure if they will be but yes they could. – David Manners Jul 25 '14 at 14:40
  • 2
    @JulienLachal. I can confirm that they are updated. There was a change in Varien_Io_File in the upgrade from ce-1.8.0.0` to ce-1.8.1.0 that screwed up one of my extensions. – Marius Jul 25 '14 at 14:42
  • @Marius ok thanks for the info, I'll try to keep that in mind if I update ;) – Julien Lachal Jul 28 '14 at 7:26
1

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.

  • seems that you can change the element types looking at _getAdditionalElementTypes the admin form for customers uses their own version for file and image. – David Manners Jul 25 '14 at 14:46
  • Marius & David,can we try this??? – Amit Bera Jul 25 '14 at 14:49
  • @DavidManners. That is what I was referring to, but make sure that there are no classes extending them. In that case, you're in trouble. – Marius Jul 25 '14 at 14:50
  • @Marius guess in this way it works for one of rewrites. If you are adding new forms this would work nicely. – David Manners Jul 25 '14 at 14:51
  • @Marius guess I could always send a bug report to Magento and wait ;) – David Manners Jul 25 '14 at 14:57
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.