/** * Function to build menu * * @param boolean $json by default output is html * @param boolean $navigationMenu true when called for building top navigation menu * * @return returns html or json object * @static */ static function buildNavigation($json = FALSE, $navigationMenu = TRUE) { $navigations = array(); self::buildNavigationTree($navigations, $parent = NULL, $navigationMenu); $navigationString = NULL; // run the Navigation through a hook so users can modify it CRM_Utils_Hook::navigationMenu($navigations); $i18n = CRM_Core_I18n::singleton(); //skip children menu item if user don't have access to parent menu item $skipMenuItems = array(); foreach ($navigations as $key => $value) { if ($json) { if ($navigationString) { $navigationString .= '},'; } $data = $value['attributes']['label']; $class = ''; if (!$value['attributes']['active']) { $class = ', "attr": { "class" : "disabled"} '; } $l10nName = $i18n->crm_translate($data, array('context' => 'menu')); $navigationString .= ' { "attr": { "id" : "node_' . $key . '"}, "data": { "title":"' . $l10nName . '"' . $class . '}'; } else { // Home is a special case if ($value['attributes']['name'] != 'Home') { $name = self::getMenuName($value, $skipMenuItems); if ($name) { //separator before if (isset($value['attributes']['separator']) && $value['attributes']['separator'] == 2) { $navigationString .= '<li class="menu-separator"></li>'; } $removeCharacters = array('/', '!', '&', '*', ' ', '(', ')', '.'); $navigationString .= '<li class="menumain crm-' . str_replace($removeCharacters, '_', $value['attributes']['label']) . '">' . $name; } } } self::recurseNavigation($value, $navigationString, $json, $skipMenuItems); } if ($json) { $navigationString = '[' . $navigationString . '}]'; } else { // clean up - Need to remove empty <ul>'s, this happens when user don't have // permission to access parent $navigationString = str_replace('<ul></ul></li>', '', $navigationString); } return $navigationString; }
/** * Function to build menu * * @param boolean $json by default output is html * * @return returns html or json object * @static */ static function buildNavigation($json = false) { $navigations = array(); self::buildNavigationTree($navigations, $parent = NULL); $navigationString = null; // run the Navigation through a hook so users can modify it require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::navigationMenu($navigations); //skip children menu item if user don't have access to parent menu item $skipMenuItems = array(); foreach ($navigations as $key => $value) { if ($json) { if ($navigationString) { $navigationString .= '},'; } $data = $value['attributes']['label']; $class = ''; if (!$value['attributes']['active']) { $class = ', attributes: { "class" : "disabled"} '; } $navigationString .= ' { "attr": { "id" : "node_' . $key . '"}, "data": { "title":"' . $data . '"' . $class . '}'; } else { // Home is a special case if ($value['attributes']['name'] != 'Home') { $name = self::getMenuName($value, $skipMenuItems); if ($name) { $removeCharacters = array('/', '!', '&', '*', ' ', '(', ')', '.'); $navigationString .= '<li class="menumain crm-' . str_replace($removeCharacters, '_', $value['attributes']['label']) . '">' . $name; } } } self::recurseNavigation($value, $navigationString, $json, $skipMenuItems); } if ($json) { $navigationString = '[' . $navigationString . '}]'; } else { // clean up - Need to remove empty <ul>'s, this happens when user don't have // permission to access parent $navigationString = str_replace('<ul></ul></li>', '', $navigationString); } return $navigationString; }