Magento CE 1.9.0.1 – Add Custom Block to Existing Tab in Catalog Product Edit View

catalogce-1.9.0.1producttabs

I need to add some content to the top of the images tab in the catalog product edit view. I do not want to add a new tab, i want to include some content (custom block) to the existing one.

I have seen a lot of tutorials on how to add a whole new tab, but nothing on how to edit an existing one.

I have managed to create an observer on the event "core_block_abstract_prepare_layout_after":

<core_block_abstract_prepare_layout_after>
      <observers>
          <edit_images_tab>
              <type>singleton</type>
                  <class>custom_module/observer</class>
                  <method>editImagesTab</method>
          </edit_images_tab>
      </observers>
</core_block_abstract_prepare_layout_after>

and remove and recreate the tab in the same position:

public function editImagesTabs(Varien_Event_Observer $observer) {
    $block = $observer->getEvent()->getBlock();

    if ($block instanceof Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs) {
        $block->removeTab('group_10');

        $block->addTabAfter(
            'group_10',
            array(
                'label'     => 'Upload Product Files',
                'content'   => $block->getLayout()->createBlock('adminhtml/catalog_product_helper_form_gallery_content')->toHtml() . 'custom content'
            ),
            'group_9'
        );
    }
}

Anyway, it seems that $block->getLayout()->createBlock('adminhtml/catalog_product_helper_form_gallery_content')->toHtml() is not enough to recreate the images tab.

Not sure if i'm going in the right direction.

Any hint would be greatly appreciated.

Best Answer

I've found another way to achieve my goal, here is what I did.

I have overridden the method toHtml() of the class "Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery" in that way:

class Custom_Module_Block_Adminhtml_Catalog_Product_Helper_Form_Gallery 
    extends Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery {

    public function toHtml() {

        $myBlock = Mage::getSingleton('core/layout')->createBlock('custom_module/custom_block')->toHtml();

        return $myBlock . parent::toHtml();
    }
}

and added this in the config.xml file:

<global>
    <blocks>
        <adminhtml>
            <rewrite>
               <catalog_product_helper_form_gallery>Custom_Module_Block_Adminhtml_Catalog_Product_Helper_Form_Gallery</catalog_product_helper_form_gallery>
            </rewrite>
        </adminhtml>
    </blocks>
</global>

not sure if this is the best approach but it works.