By default you can see «Orders» and «Amounts» tabs at the top-right of Magento administrator’s dashboard. It turned out it is not quite easy to add another one. All tabs in Magento admin (tabs at the product management, order management and apparently dashboard tabs) are widget blocks controlled by Mage_Adminhtml_Block_Widget_Tabs class. This class contains various methods for creating, maintaining and populating tabs set. In case of Magento admin dashboard there is another class Mage_Adminhtml_Block_Dashboard_Diagrams which extends Mage_Adminhtml_Block_Widget_Tabs class. This class outputs the complete unordered list with tabs and unfortunately there is absolutely no hook to put another tab inside of this list but to override _prepareLayout() method of this class.
So first we have to create a new Magento extension:
[xml title=»app/etc/Namespace_Module.xml»][/xml]
The configuration file includes the Mage_Adminhtml_Block_Dashboard_Diagrams class override and the general blocks definition of the extension:
[xml title=»app/code/community/Namespace/Module/etc/config.xml»][/xml]
Next we define the override class itself. It overrides the single module calling the parent method first and then calling the addTab method once again. The third element of parameters array is optional and used to set the new tab as active:
[php title=»app/code/community/Namespace/Module/Block/Dashboard/Diagrams.php»] addTab(‘test’, array(‘label’ => $this->__(‘Test’),
‘content’ => $this->getLayout()->createBlock(‘Namespace_Module_Block_View’)->toHtml(),
‘active’ => true
));
}
}
?>
[/php]
The next step is to create the class for the block that will be inside the tab. Quite basic one:
[php title=»app/code/community/Namespace/Module/Block/View.php»] setTemplate(‘namespace/module/index.phtml’);}
}
?>
[/php]
And the template file itself:
[html title=»app/design/adminhtml/default/default/template/namespace/module/index.phtml»]__(‘Test’) ?>
That’s all. Hope you will find it useful.
Schreibe einen Kommentar