I'm trying to develop a module which will hide selected product edit tabs for a particular user role when they are logged into the administration panel (Catalog> Products< Edit).
I have the code below, and I can tell the module is active but the module is having no affect at the moment and I'm not sure where I am going wrong.
config.xml
<?xml version="1.0"?>
<config>
<modules>
<tww_RemoveProductTabs>
<version>0.1.0</version>
</tww_RemoveProductTabs>
</modules>
<global>
<models>
<tww_RemoveProductTabs>
<class>tww_RemoveProductTabs_Model</class>
</tww_RemoveProductTabs>
</models>
<events>
<core_block_abstract_prepare_layout_after>
<observers>
<tww_RemoveProductTabs>
<class>tww_RemoveProductTabs/observer</class>
<method>removeTabs</method>
<type>singleton</type>
<tww_RemoveProductTabs>
</observers>
</core_block_abstract_prepare_layout_after>
</events>
</global>
</config>
tww_RemoveProductTabs.xml
<?xml version="1.0"?>
<config>
<modules>
<tww_RemoveProductTabs>
<active>true</active>
<codePool>local</codePool>
</tww_RemoveProductTabs>
</modules>
</config>
Observer.php
<?php
class tww_RemoveProductTabs_Model_Observer
{
public function removeTabs(Varien_Event_Observer $observer)
{
// Get the users role id
$admin_user_session = Mage::getSingleton('admin/session');
$adminuserId = $admin_user_session->getUser()->getUserId();
$role_data = Mage::getModel('admin/user')->load($adminuserId)->getRole()->getData();
// if lower admin user
if($role_data == 4)
{
$tabBlock = $evt->getEvent()->getBlock();
if ($tabBlock instanceof Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs)
{
$tab_ids = $tabBlock->getTabsIds();
$tabs_to_hide = array('inventory');
foreach ($tab_ids as $tab)
{
if(in_array($tab, $tabs_to_hide))]
{
$tabBlock->removeTab($tab);
}
else
{
$tabBlock->setActiveTab($tab);
}
}
}
// tesing
$tabBlock->removeTab('related');
}
}
}
Any ideas would be greatly appreciated. Thanks.