Jump to content

BO Tab & sub Tab Installation


CGregory

Recommended Posts

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

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

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

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

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

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 said
I 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

47903_lUlzMPutR24uDLThO0LJ_t

Link to comment
Share on other sites

  • 11 years later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...