2
0
forked from Wavyzz/dolibarr

add hook 'menu_LeftMenuArray' to filter the leftmenu items

This commit is contained in:
Christian Foellmann
2021-07-30 13:15:01 +02:00
parent 583f1ccc1a
commit 0102e73306
2 changed files with 26 additions and 3 deletions

View File

@@ -193,6 +193,7 @@ class HookManager
'getFormatedSupplierRef',
'getIdProfUrl',
'getInputIdProf',
'menu_LeftMenuItems',
'moveUploadedFile',
'moreHtmlStatus',
'pdf_build_address',

View File

@@ -688,9 +688,9 @@ function print_end_menu_array()
* @param int $type_user 0=Menu for backoffice, 1=Menu for front office
* @return int Nb of menu entries
*/
function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null, $type_user = 0)
{
global $user, $conf, $langs, $dolibarr_main_db_name, $mysoc;
function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null, $type_user = 0) {
global $user, $conf, $langs, $dolibarr_main_db_name, $mysoc, $hookmanager;
//var_dump($tabMenu);
@@ -1958,6 +1958,28 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM
return 0;
}
// Allow the $menu_array of the menu to be manipulated by modules
$parameters = array(
'mainmenu' => $mainmenu,
);
$hook_items = $menu_array;
$reshook = $hookmanager->executeHooks('menu_LeftMenuArray', $parameters, $hook_items); // Note that $action and $object may have been modified by some hooks
if (is_numeric($reshook)) {
if ($reshook == 0 && !empty($hookmanager->results)) {
$menu_array[] = $hookmanager->results; // add
} elseif ($reshook == 1) {
$menu_array = $hookmanager->results; // replace
}
// @todo Sort menu items by 'position' value
// $position = array();
// foreach ($menu_array as $key => $row) {
// $position[$key] = $row['position'];
// }
// array_multisort($position, SORT_ASC, $menu_array);
}
// TODO Use the position property in menu_array to reorder the $menu_array
//var_dump($menu_array);
/*$new_menu_array = array();