Merge pull request #18297 from cfoellmann/hook-menu

NEW add hook 'menuLeftMenuItems' to filter the leftmenu items
This commit is contained in:
Laurent Destailleur 2021-07-31 16:13:49 +02:00 committed by GitHub
commit 0c024ca96b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

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

View File

@ -690,7 +690,8 @@ function print_end_menu_array()
*/
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;
global $user, $conf, $langs, $dolibarr_main_db_name, $mysoc, $hookmanager;
//var_dump($tabMenu);
@ -1958,6 +1959,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('menuLeftMenuItems', $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();