CGregory Posted June 19, 2011 Share Posted June 19, 2011 I have been researching and trial / error the past few days to install a new module with BO Tab and Sub Tabs. I can get the module to install the main Tab (parent ID 0) however I cannot get the sub tab to be created under the Parent tab I created just before it. I have tried to use the Tab::getIdFromClassName('TestTab')) , TestTab being the class name of the Main Tab I want to show on the Tab bar in the BO.I want to create a Main Tab and 3 sub tabs when the module is installed. Is this possible or do I have to create a module per sub tab I want?Any help is appreciated. Link to comment Share on other sites More sharing options...
shokinro Posted June 19, 2011 Share Posted June 19, 2011 I want to create a Main Tab and 3 sub tabs when the module is installed. Is this possible or do I have to create a module per sub tab I want? No, you don't have to create 3 module for the purpose of creating 3 tabs.You can just use the Tab class and set related property and call save() method, that's it. Link to comment Share on other sites More sharing options...
CGregory Posted June 19, 2011 Author Share Posted June 19, 2011 This is what I got and it does not add the sub tab under the main tab. Any incite? public function install() { if(!parent::install() || !Configuration::updateValue('MOD_REPAIRSHOP_IMG', _PS_MODULE_DIR_.$this->name.'/logo.gif') || !$this->installModuleTab('AdminTestMod', array(1=>'Test Mod'), 0) || !$this->installModuleTab('AdminTestModSub1', array(1=>'Sub 1'), Tab::getIdFromClassName('AdminTestMod'))) return false; return true; } and the normal install function private function installModuleTab($tabClass, $tabName, $idTabParent) { @copy(_PS_MODULE_DIR_.$this->name.'/logo.gif', _PS_IMG_DIR_.'t/'.$tabClass.'.gif'); $tab = new Tab(); $tab->name = $tabName; $tab->class_name = $tabClass; $tab->module = $this->name; $tab->id_parent = $idTabParent; if(!$tab->save()) return false; return true; } Link to comment Share on other sites More sharing options...
shokinro Posted June 19, 2011 Share Posted June 19, 2011 you can not guarantee that installModuleTab('AdminTestMod', array(1=>'Test Mod'), 0) is executed before $this->installModuleTab('AdminTestModSub1', array(1=>'Sub 1'), Tab::getIdFromClassName('AdminTestMod')) in following code. if(!parent::install() || !Configuration::updateValue('MOD_REPAIRSHOP_IMG', _PS_MODULE_DIR_.$this->name.'/logo.gif') || !$this->installModuleTab('AdminTestMod', array(1=>'Test Mod'), 0) || !$this->installModuleTab('AdminTestModSub1', array(1=>'Sub 1'), Tab::getIdFromClassName('AdminTestMod'))) return false; Link to comment Share on other sites More sharing options...
CGregory Posted June 19, 2011 Author Share Posted June 19, 2011 I gathered that. Any ideas? Link to comment Share on other sites More sharing options...
CGregory Posted June 20, 2011 Author Share Posted June 20, 2011 So its possible but no one knows how or will tell how? Link to comment Share on other sites More sharing options...
CGregory Posted June 22, 2011 Author Share Posted June 22, 2011 Come on. I get a reply back saying its possible but yet you don't clarify how. Do you even know for sure it is possible or you just trying to sound like you do? If its possible a little bit of help is all I am asking. Link to comment Share on other sites More sharing options...
shokinro Posted June 22, 2011 Share Posted June 22, 2011 Do you even know for sure it is possible or you just trying to sound like you do? Hi my friend, assume I am pretending to know.I suggested you separate call in different statement.you can not guarantee that installModuleTab(‘AdminTestMod’, array(1=>‘Test Mod’), 0) is executed before $this->installModuleTab(‘AdminTestModSub1’, array(1=>‘Sub 1’), Tab::getIdFromClassName(‘AdminTestMod’)) in following code. but you saidI gathered that. Any ideas? If its possible a little bit of help is all I am asking. Here is my test code that will create 3 tabs : 1 main, other 2 sub tab, it is tested in PS 1.4.1, $tab = new Tab(); $tab->id_parent = 0; $languages = Language::getLanguages(); foreach ($languages AS $language) { $tab->{'name'}[intval($language['id_lang'])] = 'Test1'; } $tab->class_name = 'AdminTest1'; if(!$tab->add())print "failed"; else print "succeed"; $parentID = $tab->id; $tab = new Tab(); $tab->id_parent = $parentID; $languages = Language::getLanguages(); foreach ($languages AS $language) { $tab->{'name'}[intval($language['id_lang'])] = 'Test11'; } $tab->class_name = 'AdminTest11'; if(!$tab->add())print "failed"; else print "succeed"; $tab = new Tab(); $tab->id_parent = $parentID; $languages = Language::getLanguages(); foreach ($languages AS $language) { $tab->{'name'}[intval($language['id_lang'])] = 'Test12'; } $tab->class_name = 'AdminTest12'; if(!$tab->add())print "failed"; else print "succeed"; and attached is the screenshot of the result Link to comment Share on other sites More sharing options...
CGregory Posted June 28, 2011 Author Share Posted June 28, 2011 cool deal, I will give that a try tonight. Thanks. Link to comment Share on other sites More sharing options...
Ali Samie Posted October 31, 2022 Share Posted October 31, 2022 Add custom tab for a custom admin controller in a custom module: 1. create controller file in this path: mymodule/controllers/admin/CustomController.php 2. add this property to your module: $tabs = [ 'class_name' => 'Custom', 'parent_class_name' => 'AdminParentCustomerThreads', //It can be any parent from this list https://devdocs.prestashop-project.org/1.7/modules/concepts/controllers/admin-controllers/tabs/#which-parent-to-choose 'visible' => true // If you want an admin controller for ajax calls only, you can set this to false ]; More details about attributes of this $tabs property are here: https://devdocs.prestashop-project.org/1.7/modules/concepts/controllers/admin-controllers/tabs/#how-to-define-a-tab-in-the-menu Important note: Pay attention to the name of the file. In this example, file name is 'CustomController.php' and in $tabs property we have a 'class_name' which is set to 'Custom'. No 'Controller' is added at the end. If you add this, it fails to add the tab Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now