Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I am wondering, is there any way to add a custom fieldset to an admin form, without overwriting Form container class of that admin-form.

I will explain it little bit. Suppose we need to add a new fieldset in CMS_Block. We can achieve this by rewrite _preapreForm() method of class Mage_Adminhtml_Block_Cms_Block_Edit_Form. Here we need to do somewhat this in order to achieve our goal

class Namespace_Modulename_Block_Adminhtml_Cms_Block_Edit_Form extends Mage_Adminhtml_Block_Cms_Block_Edit_Form{

    protected function _prepareForm()
    {
        parent::_prepareForm();

        /*
           add new fieldset and fields here
        */
    }
}

However I don't like to do rewrite of a core class (Since Its not a good practice). Is there any other approach exist to achieve the same result. I just want to add a new field sets with a custom module on an admin form with two conditions

  1. Without touching core files

  2. Without doing rewrite

Eagerly waiting for your responses.

share|improve this question
    
What is about layout update? Or using event for specific controller/action render? –  Amasty Aug 13 at 10:27
    
@Amasty layout update wont work. Please review the answer that marius made –  programmer_rkt Aug 13 at 10:28

1 Answer 1

up vote 3 down vote accepted

You can try to observe the event adminhtml_block_html_before.
but that gets dispatched for every block that is a child of Mage_Adminhtml_Block_Template.
So you will need to to a check first to see if the block matches your need.
something like this:

public function addFields($observer) {
    $block = $observer->getEvent()->getBlock();
    if ($block instanceof Mage_Adminhtml_Block_Cms_Block_Edit_Form) {
         //do your magic here
    }
}
share|improve this answer
    
observers are better than rewrite. But still its not a clean method. Coz almost every admin blocks are child of Mage_Admin_Html_Template. Is there any way to achieve this through layout ? But when I deeply thinking about it, it gave me a feeling that, my block would include outside of the form. @marius –  programmer_rkt Aug 13 at 10:24
    
@programmer_rkt I don't think there is a way to do it through layout files. The block in question does not appear in the layout files. It is instantiated via the parent block. –  Marius Aug 13 at 10:26
    
and secondly I have a friendly question to you. Which method you normally adopt to do this job? –  programmer_rkt Aug 13 at 10:26
    
So as per your suggestion, there is probably these two ways exist to do this right ? –  programmer_rkt Aug 13 at 10:29
    
i suggest that this as event every time for admin block,if you add controller full action name as ccondtion then it it be better.....$action = Mage::app()->getFrontController()->getAction(); $action->getFullActionName() if($action->getFullActionName()='adminhtml_cms_block_edit){ // marius code } –  Amit Bera Aug 13 at 10:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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