Tabs system

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search

The system of Dolibarr tabs

Dolibarr showns information of an element into a view with several tabs.

It is possible to add your own tabs, remove or replace an existing tabs or replace.

To add your own tab

1) First, you must identify the type of object your tab is about, and its objecttype code. This is full list:

  • 'thirdparty' to add a tab in third party view
  • 'intervention' to add a tab in intervention view
  • 'supplier_order' to add a tab in supplier order view
  • 'supplier_invoice' to add a tab in supplier invoice view
  • 'invoice' to add a tab in customer invoice view
  • 'order' to add a tab in customer order view
  • 'product' to add a tab in product view
  • 'stock' to add a tab in stock view
  • 'propal' to add a tab in propal view
  • 'member' to add a tab in fundation member view
  • 'contract' to add a tab in contract view
  • 'user' to add a tab in user view
  • 'group' to add a tab in group view
  • 'contact' to add a tab in contact view
  • 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
  • 'member_stats', 'order_stats', 'supplier_order_stats', 'invoice_stats', 'supplier_invoice_stats', 'trip_stats', 'propal_stats' to add a tab in statistic view of elements.
  • 'member_admin', 'company_admin', 'product_admin' for admin pages

2) Then to add your tab, create a new module descriptor file. See page Module development for this.

3) Then into the descriptor file, edit the property this->tab to add your tab using following syntax:

$this->tabs = array(
'objecttype:+tabname:TitleOfTab:@mymodule:$conditiontoshowtab:urloftab?id=__ID__'
);

This is a string composed of 5 or 6 elements (depending whether you choose to use a $conditiontoshowtab) separated by semicolons.

Where:

  • objecttype is the name of the tabhook you will use.
  • +tabname is a name you choose to identify your tab, preceded by the action (either + to add, or - to remove, and you can remove other tabs as well including default ones).
  • TitleOfTab is a title you choose, it will be translated
  • @mymodule is the language file where your translation (of the title) resides (eg: mytitlelang@mymodule will look inside /htdocs/mymodule/langs/xx_XX/mytitlelang and where xx_XX is the current localization of Dolibarr, eg: en_US, fr_FR, etc.).
  • $conditiontoshowtab is a variable that will be eval'd to get the value: if true then the tab is shown, if false then the tab won't be. Eg: you can use the Dolibarr rights system, eg: $user->rights->product->creer or $user->admin or any other variable you want. This is optional, you can just skip this and leave only 5 elements in this string and it will work (don't forget to remove the semicolon too).
  • urloftab?id=__ID__ is the URL where the tab will point to when clicked. You can use the placeholder __ID__ which will be replaced by the value of the id if one is defined. Eg: DOL_DOCUMENT_ROOT.'/mymodule/lib/mytab.php'


Example:

$this->tabs = array(
'product:+tabname1:Title1:@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__',     // To add a new tab identified by code tabname1 in objecttype product (Products/Services)
'product:+tabname2:Title2:@mymodule:$user->rights->othermodule->read:/mymodule/mynewtab2.php?id=__ID__',  // To add another new tab identified by code tabname2 in objecttype product (Products/Services)
);

4) Activate module

5) Test new tabs is visible and link open your page.

To remove an existing tab

Process is same than adding a tab, put into the tab array of descriptor the following syntax:

$this->tabs = array(
'objecttype:-tabname'
);                                                     // To remove an existing tab identified by code tabname

Note: the other parameters are not needed in this case.

To replace a tab with yours

Just do step "To add your own tab" and process "To remove an existing tab". If the title of your new tab is same as the title of the removed one, illusion is perfect.

To show tabs into your own page

More information on how to show tabs into your own pages is available on page Module_development#The_tab_management