Developing a custom module

Hello all,
I have developed a custom module and everything is good now but now when i’m creating an external user related to a specific third party, this user can’t see this module index page in the top menu even he can see it inside the third party module and for sure the internal user can see it without any problems. I gave this external user the permissions and also in the mod file in the “$this->menu” also i gave the “perms” parameters the value “2” which means that both internal and external users can see it. Do anyone know why it still not working?

@ksar please help me with this

@muhannedzo
I know that this is an old question, but did you ever get this working for you?

I am wondering if you needed to deactivate/reactivate your module?

If so, I am wondering what your top menu code looks like in the mod class.

Hey @playcock Actually no it didn’t work and also i activated and deactivated the module many times but nothing changed. I read that in Dolibarr few modules are allowed to be accessed in the top bar by external users, for internal users they can see it clearly.

You may want to check the permission settings for a directory or file (for example, user: root, permissions: 755). Another option may be to enable support for external users in your modXXXX.class.php file.

@itispartner believe me i did everything possible but still the same.

		$this->menu[$r++] = array(
			'fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
			'type'=>'top', // This is a Top menu entry
			'titre'=>'ModuleStoresName',
			'prefix' => 'fas fa-store',
			'mainmenu'=>'stores',
			'leftmenu'=>'',
			'url'=>'/stores/storesindex.php',
			'langs'=>'stores@stores', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
			'position'=>1000 + $r,
			'enabled'=>'$conf->stores->enabled', // Define condition to show or hide menu entry. Use '$conf->stores->enabled' if entry must be visible if module is enabled.
			'perms'=>'$user->rights->stores->branch->read', // Use 'perms'=>'$user->rights->stores->branch->read' if you want your menu with a permission rules
			'target'=>'',
			'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
		);

this is the code which will give the permissions and also it’s not working. Also, the prefix isn’t working even that i’m giving it a value of an icon.
Also you can check this note

you can try change your code like this

//----
// To use a supported fa-xxx css style of font awesome, use this->picto='xxx'
$this->picto = 'fas fa-store';

//----

$this->menu[$r++] = array(
			'fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
			'type'=>'top', // This is a Top menu entry
			'titre'=>'ModuleStoresName',
			'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth valignmiddle"'),
			'mainmenu'=>'stores',
			'leftmenu'=>'',
			'url'=>'/stores/storesindex.php',
			'langs'=>'stores@stores', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
			'position'=>1000 + $r,
			'enabled'=>'isModEnabled("stores")',
			'perms'=>1,
			'target'=>'',
			'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
		);

@muhannedzo
In your custom module’s modXXXX.class.php file, look for $this->module_parts and make sure that moduleforexternal is set to 1, like so

// Set this to 1 if features of module are opened to external users
'moduleforexternal' => 1,

Then deactivate/reactivate your module.

@itispartner Might have been referring to this in comment #5

1 Like

@playcock many thanks!! it’s now working!
Now do you have any idea how to show the icon of the module in the top menu? i tried to set the $this->picto but it’s not working
Also thanks @itispartner

@muhannedzo
I haven’t got too deep with the icon.

I just set this value on the menu object:
'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth valignmiddle"'),

Then I make sure that $this->picto has the vale of ‘generic’. This is usually set before $this->module_parts in the modXXXX.class.php file. There are some comments about it that might help with customizing the icon that you might find useful.

// Name of image file used for this module.
// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
// To use a supported fa-xxx css style of font awesome, use this->picto='xxx'
$this->picto = 'generic';