Need explanation of the usage of fk_mainmenu, fk_leftmenu, mainmenu and leftmenu in Module Building

as per title, I am building a module and need a more thorough explanation of how mainmenu, leftmenu, fk_menu work. In the documentation (the only one I could find) and directly in the code comments I found only this:

For left menu, use ‘fk_mainmenu=xxx’ or ‘fk_mainmenu=xxx,fk_leftmenu=yyy’ where xxx is mainmenucode and yyy is a leftmenucode.

Written this way, it is not clear what they do; it is not explained what mainmenucode and leftmenucode are or where they can be found.
It is not explained what mainmenu and leftmenu are for, it just seems like repetition.

Need a detailed explanation of how to create a side menu, how to create dividers, subheadings

Thanks

Hello, i think like you: the official documentation is really not enough. But i can share with you (and future people searching about this) how i get it run :hugs:

For example, in my module Ticket Plus to get this on the LEFT menu of the “Ticket” native module:

  • a “title” element with icon: “HelpDesk
  • a “link” element: “Public Portal
  • a “link” element, under “Knowledge base” group (native module): “Searches with AI

image

i have defined this code on the file /custom/ticketplus/core/modules/modTicketplus.class.php

$this->menu[$r]=array(
	'fk_menu'=>'fk_mainmenu=ticket',
	'type'=>'left',
	'titre'=>'HelpDesk',
	'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'),
	'mainmenu'=>'ticket',
	'leftmenu'=>'ticketplus',
	'url'=>'',
	'langs'=>'ticketplus@ticketplus',
	'position'=>20,
	'enabled'=>'1',
	'perms'=>'',
	'target'=>'',
	'user'=>0);
$r++;
$this->menu[$r]=array(
	'fk_menu'=>'fk_mainmenu=ticket,fk_leftmenu=ticketplus',
	'type'=>'left', // This is a Left menu entry
	'titre'=>'ticketplusLeftMenu1',
	'mainmenu'=>'ticket',
	'leftmenu'=>'',
	'url'=> $url,
	'langs'=>'ticketplus@ticketplus',
	'position'=>21,
	'enabled'=>'1',
	'perms'=>'',
	'target'=>'',
	'user'=>0);

$r++;
$this->menu[$r]=array(
	'fk_menu'=>'fk_mainmenu=ticket,fk_leftmenu=knowledgemanagement_knowledgerecord',
	'type'=>'left',
	'titre'=>'ticketplusLeftMenu2',
	'mainmenu'=>'ticket',
	'leftmenu'=>'knowledgemanagement_list',
	'url'=> '/ticketplus/article_search_list.php',
	'langs'=>'ticketplus@ticketplus',
	'position'=>113,
	'enabled'=>'$conf->knowledgemanagement->enabled',
	'perms'=>'$user->rights->knowledgemanagement->knowledgerecord->read',
	'target'=>'',
	'user'=>0);

Conclusions to be extracted:

  • 'mainmenu'=>'ticket' is used in all 3 elements to indicate tha they must appear when mainmenu=ticket appears in the URL
  • 'type'=>'left' is used in all 3 elements to indicate that we want to render it on the left vertical panel, no at the top menu panel
  • the attribute leftmenu is not very clear to me. I think that i can define here a non-existing value, and then it will serve as “anchor” where to hang/group other items, for example when the first element to use it is of type “title” (= no url defined). Or you can also define here an existing leftmenu (like ‘leftmenu’=>‘knowledgemanagement_list’) to make define this element as a child of an existing one.
  • once setted the previous points, then you must build the fk_menu attribute, as you said, something redundant: combining mainmenu and leftmenu values.
  • regarding to TEXT TRANSLATIONS, take in account that if you are using your language module files then you must set this attribute: 'langs'=>'ticketplus@ticketplus' (where “ticketplus” must be the main directory name of your module) and set this for element text: 'titre'=>'ticketplusLeftMenu1' (where this is one of the text tags defined on your language files)

I hope this put more light on what to get it work in your case!

Cheers,
Sergi

2 Likes

thank you for your response Sergi,
I will use your information to improve my side menu and if I find out other things I will put them in a comment.
It is a pity that the documentation sins a lot in some places, dolibarr is a great software, if it was also easily maintainable we would all be happier

Hi all
This is a community effort and ideally everyone should share knowledge.
If you can improve the documentation instead of comments.
Thanks

I will add a comment to make sure that if someone ended up in this thread they would still have the information they are looking for.
If I can retrieve enough information and make sure it is 100% correct I will bother to update the documentation, assuming I have the ability to do so.

Of course, no one could fix the documentation better than the person who created that portion of the code

1 Like