Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: How to get magento fieldset from existing form in admin within observer

I'm having problems when trying to get fieldset in existing admin form in observer. I'm getting the form but when I try to get fieldset I'm getting nice error: Fatal error: Call to a member function addField() on a non-object When I add this new field straight to form everything is fine except that it is outside fieldset.

$form = $observer->getBlock()->getForm();
$fieldset = $form->getFieldset('fieldset_id');
$fieldset->addField('some_field', 'text', array(
    'name' => 'some_field',
    'label' => Mage::helper('cms')->__('Some Field'),
    'title' => Mage::helper('cms')->__('Some Field')
  )
);
like image 483
Marceli Po Avatar asked Feb 20 '13 16:02

Marceli Po


1 Answers

Ok I did it. It was my bad. I took wrong block type. Here is the code:

public function onAdminhtmlBlockHtmlBefore(Varien_Event_Observer $observer)
{
    $block = $observer->getBlock();
    if (!isset($block)) return;

    switch ($block->getType()) {
    case 'adminhtml/some_edit_tab_main':
    $form = $block->getForm();
        $fieldset = $form->getElement('base_fieldset');
        $fieldset->addField('some_field', 'text', array(
                'name' => 'some_field',
                'label' => Mage::helper('cms')->__('Some Field'),
                'title' => Mage::helper('cms')->__('Some Field')
            )
        );
        break;
    }
}
like image 158
Marceli Po Avatar answered Oct 03 '22 01:10

Marceli Po