Recently I struggled with how to set an active tab after hiding the first one in Magento admin custom module. I wanted to have the view and edit tabs inside the same action, so that when it edits the page both view and edit are shown. When it’s a new action then only the edit tab will be shown (with corresponding title). Sadly, searching the internet gave me zero results, so it was time to make it by myself.
So, I’ve hide view tab when it’s new action:
1 2 3 4 5 6 7 8 9 10 11 12 |
/* app/code/local/NameSpace/ModuleName/Block/Adminhtml/Items/Edit/Tab/View.php */ .... public function canShowTab() { if ($this->getItem()->getId()) { return true; } return false; } .... |
Result:
To set this tab as active you need to add following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* app/code/local/NameSpace/ModuleName/Block/Adminhtml/Items/Edit/Tabs.php */ .... protected function _beforeToHtml() { $item = Mage::registry('item_model'); if (!$item->getId()) { $this->setActiveTab('section_edit'); } return parent::_beforeToHtml(); } .... |
And voila:
Hope that helps.