0

I have overridden a core file with my own file. This part is working correctly.

<adminhtml>
    <rewrite>
       <catalog_category_tabs>MyModule_Adminhtml_Block_Tabs</catalog_category_tabs>
    </rewrite>
</adminhtml>

However when trying to add a custom tab with a block for content, I'm running into issues.

class MyModule_Adminhtml_Block_Tabs extends Mage_Adminhtml_Block_Catalog_Category_Tabs
    protected function _prepareLayout()
    {
        // ...
        // dispatch event add custom tabs
         Mage::dispatchEvent('adminhtml_catalog_category_tabs', [
            'tabs' => $this,
        ]);

        // My tab
        $this->addTab('custom', [
            'label'   => Mage::helper('catalog')->__('Custom Tab'),
            'content' => $this->getLayout()->createBlock(
                'adminhtml/tab_custom',
                'category.custom.grid'
            )->toHtml(),
        ]);

        return parent::_prepareLayout();
    }

The createBlock method is returning false.

The referenced file is at MyModule/Adminhtml/Block/Tab/Custom.php. Is there something I'm missing?

1 Answer 1

1

In magento, rewrite not means to rewrite all file under in this class.

In there,you have trying to call block class MyModule/Adminhtml/Block/Tab/Custom.php using block type adminhtml/tab_custom.

Using adminhtml/tab_custom block type magento call block class Mage_Adminhtml_Block_Tab_Custom .And that class does not exit at system. that why you did not get false return.

Solution

- Define block type for your module

define the block type of module MyModule_Adminhtml ,so that class this block class by a block type:

<global>
<blocks>
    <mymodule>
    <class>MyModule_Adminhtml_Block</class>
    </mymodule>
    <adminhtml>
        <rewrite>
           <catalog_category_tabs>MyModule_Adminhtml_Block_Tabs</catalog_category_tabs>
        </rewrite>
    </adminhtml>            
</blocks>
</global> 

call that MyModule/Adminhtml/Block/Tab/Custom.php by block type

mymodule/tab_custom.

So change adminhtml/tab_custom to mymodule/tab_custom

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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