Adding/Modifying the Shortcuts Menu
29 Jun, 2009Posted By: Lam
Adding/Modifying the Shortcuts Menu
Suppose you want to modify the Opportunities Shortcuts menu to add a shortcut to create a new Lead (not tied to the existing opportunity).
Create a custom file called:
/custom/Extension/modules/Opportunities/Ext/Menus/CustomMenu.php
The filename is not very important. Add the following contents:
<?php
if(ACLController::checkAccess(’Leads’, ‘edit’, true))$module_menu[]=Array(”index.php?module=Leads&action=EditView&return_module=Opportunities&return_action=ListView”, “New From Canvass Form”,”CreateNotes”, ‘Leads’);
?>
Lets’s look at this code to see what it does.
if(ACLController::checkAccess(’Leads’, ‘edit’, true))
This line of code checks to see if the user has access to the Leads module. If they do then the system will all another shortcut menu. This is not strictly required, but good coding practice so users don’t see menu items for modules they can’t create or edit.
The variable $module_menu contains the items the information used to create the menus. The format is
$module_menu[]=Array($url,$menu_title,$image_icon,$module)
$url – this is where you want to go. You can look at <install dir>/<ModuleName>/Menu.php to see the shortcuts for the existing modules
$menu_title – In this example, I hard coded the name to “New from Canvass Form”. If you want the application to be multi-lingual and conform to Sugar standards, you should add a custom string and use something like $mod_strings['LNK_NEW_FROM_CANVASS_FORM']
$image_icon – The images are found in themes/default/images. If you want to add a new icon, put it there.
$module – The name of the module
You must do a Quick Repair and Rebuild for this to take effect.
If you want to not show the out of the box shortcut menu items, you can just redeclare the array. Putting the following code in your cusotm file:
<?php
$module_menu= array();
if(ACLController::checkAccess(’Leads’, ‘edit’, true))$module_menu[]=Array(”index.php?module=Leads&action=EditView&return_module=Opportunities&return_action=ListView”, “New From Canvass Form”,”CreateNotes”, ‘Leads’);
?>
will have only 1 shortcut item.
July 16th, 2009 at 12:47 am
It’s a bit brutal, but removing just one link from the menu can be achieved by unsetting that exact key from the array:
unset($module_menu[1]);
Off course, the menu mustn’t change or this can begin to cause troubles in the menu. Something like this should also work:
foreach($module_menu AS &$item) {
if($item === array(”index.php?module=Leads&action=EditView&return_module=Opportunities&return_action=ListView”, “New From Canvass Form”,”CreateNotes”, ‘Leads’)) {
unset($item);
}
}