Published: 2017-12-15   Views: 3647
Author: hasanuzzaman
Published in: Dolibarr
How To Define Custom Menu Entries Into Dolibarr ERP CRM

Now a days Dolibarr is an wildly used enterprise resource planning and customer relationship management software. Now latest Dolibarr version is 6.0.3. There are so many MVC structure has been changed since its initial launch. If you are a developer and you are working with this LAMP based online CRM software, nearly you may need to develop module for Dolibarr. But this module development document is not resourceful enough and it is not complete too. I am developing a module and got stuck with Dolibarr module menu entry. The current information given on the documentation is not correct or may not be complete. First bugs related to menu entry are discussed below.

 

Dolibarr module development menu entry bug

The present documentation has the following code sample for new menu entry.

// Main menu entries
$this->menu = array();			// List of menus to add
$r=0;
 
// Add here entries to declare new menus
// Example to declare the Top Menu entry:
$this->menu[$r]=array(	'fk_menu'=>0,			// Put 0 if this is a top menu
			'type'=>'top',			// This is a Top menu entry
			'titre'=>'MyModule top menu',
			'mainmenu'=>'mymodule',
			'leftmenu'=>'mymodule',
			'url'=>'/mymodule/pagetop.php',
			'langs'=>'mylangfile',	// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
			'position'=>100,
			'enabled'=>'1',			// Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
			'perms'=>'1',			// Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
			'target'=>'',
			'user'=>2);				// 0=Menu for internal users, 1=external users, 2=both
$r++;
 
// Example to declare a Left Menu entry:
$this->menu[$r]=array(	'fk_menu'=>'fk_mainmenu=xxx',		    // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode of parent menu
			'type'=>'left',			        // This is a Left menu entry
			'titre'=>'MyModule left menu 1',
			'mainmenu'=>'xxx',
                        'leftmenu'=>'yyy',
			'url'=>'/mymodule/pagelevel1.php',
			'langs'=>'mylangfile',	// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
			'position'=>100,
			'enabled'=>'1',			// Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
			'perms'=>'1',			// Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
			'target'=>'',
			'user'=>2);				// 0=Menu for internal users,1=external users, 2=both
$r++;

Please pay attention to the following line of this documentation.

$this->menu[$r]=array(	'fk_menu'=>0,			// Put 0 if this is a top menu

According to the above line, it says that the value of fk_menu element should be 0(zero) for top menu entry. This is totally incorrect. I spent about 4 hours to find this document mistake out. If your menu need an entry for top menu then the value should be the name of the module itself or any other convenient name. In my case i had change the above line to

$this->menu[$r]=array(	'fk_menu'=>'ALDictionary',			// Put 0 if this is a top menu

If you don't change this value to your module name, you will face the problem with setting left menu entry for our own module. This should solve your problem.

Positioning module menu items

Another valueable property of the menu items of it's position inside the menu. Now for top menu entry the value of position greater than 0 means the menu will be displayed to the right side of the top menu. The Dolibarr internal module system has around 150 as the value for position element. So if you want to put your custom module top menu item at the most right side, you should choose a value greater than 150 for position element. For left menu items of your module you can start the value of position element with 0(zero).

 

Sample code of working left menu items

 

$this->menu[]=array(	
		'fk_menu'=>'fk_mainmenu=topmenu', 
		'type'=>'left', 
		'titre'=>'MenuTitle',
		'mainmenu'=>'topmenu',
		'leftmenu'=>'leftmenu',  //leave it blank if you don't have any left menu group
		'url'=>'/example/example.php',
		'langs'=>'topmenu@topmenu',	
		'position'=>1,
		'enabled'=>'1', 
		'perms'=>'($user->rights->produit&&$user->rights->fournisseur)', 
		'target'=>'',
		'user'=>0);

For more information you can visit at https://www.dolibarr.org/forum/511-creation-of-a-new-module/27440-help-needed-in-left-menu-entry-of-new-module .

 

Article Comments

0 comments.

There are zero comments yet, why not be the first?

You must be logged in to post a comment.

Please log in or register to comment or reply to a comment.

Articles Search

Featured Articles

Most Popular Articles

Article Categories Expand

7  
1  
1  
1  
0  
6  
0  
53  
3  

There are zero sub-categories in this parent category.

49  
4  
6  
3  
3  
7  
4  
8  
3  
2  
1  
0  
0  
0  
26  
0  
0  
0  
1  
2  
8  
1  
1  
0  
1  
1  
0  
1  
1  
0  
0  
1  
4  
0  
3  
3  
0  
1  
25  
1  
0  
0  
1  
0  
0  
6  
0  
1  
29  
1  
0  
2  
0  
11  
0  
0  
0  
0  
3  
2  
0  
2  
2  
1  

There are zero sub-categories in this parent category.

3  
1  
2  
5  
0  
3  
2  
1  
0  
0  
1  
0  
1  
2  
0  
1  
0  
21  
0  

There are zero sub-categories in this parent category.

0  
1  
0  
0  
0  
0  
0  
1  
0  
0  
0  
2  
24  
17  
3  
1  
0  
0  
0  
0  
1  
1  
0  
0  
0  
0  
0  
1  
0  
0  
1  
3  
0  
0  
0  
0  
0  
0  
0  
1  
1  
0