function _econ_get_menu_children($path) { $parent = menu_link_get_preferred($path); $parameters = array('conditions' => array('plid' => $parent['mlid'])); $children = menu_build_tree($parent['menu_name'], $parameters); return array_values($children); }
/** * Genereate navbar menu. */ function valghalla_bs_theme_navbarmenu($path) { $parent = menu_link_get_preferred($path); $parameters = array('active_trail' => array($parent['plid']), 'only_active_trail' => FALSE, 'min_depth' => $parent['depth'] + 1, 'max_depth' => $parent['depth'] + 1, 'conditions' => array('plid' => $parent['mlid'])); $children = menu_build_tree($parent['menu_name'], $parameters); $tree_output = menu_tree_output($children); $items = array(); foreach ($tree_output as $item_id => $item_data) { if (is_numeric($item_id) && is_array($item_data)) { $items[] = l($item_data['#title'], $item_data['#href'], array('attributes' => $item_data['#attributes'], 'html' => TRUE)); } } $menu = theme('item_list', array('items' => $items, 'type' => 'ul', 'attributes' => array('class' => 'dropdown-menu'))); $toggle = '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' . $parent['link_title'] . ' <b class="caret"></b></a>'; if ($menu) { return $toggle . $menu; } }
echo '<div class="menu row" id="r' . $children["link"]["mlid"] . '">'; echo '<ul class="level3">'; foreach ($childrens2 as $children2) { $path = $children2["link"]["link_path"]; $parent = menu_link_get_preferred($path); $parameters = array('active_trail' => array($parent['plid']), 'only_active_trail' => FALSE, 'min_depth' => $parent['depth'] + 1, 'max_depth' => $parent['depth'] + 1, 'conditions' => array('plid' => $parent['mlid'])); $childrens3 = menu_build_tree($parent['menu_name'], $parameters); echo '<li class="nb' . $children2["link"]["mlid"] . '">'; $nbChildrens = count($childrens3); if ($nbChildrens > 0) { echo '<a href="#r' . $children2["link"]["mlid"] . '">' . $children2["link"]["title"] . '</a>'; echo '<div class="menu row" id="r' . $children2["link"]["mlid"] . '">'; echo '<ul class="level4">'; foreach ($childrens3 as $children3) { $path = $children3["link"]["link_path"]; $parent = menu_link_get_preferred($path); $parameters = array('active_trail' => array($parent['plid']), 'only_active_trail' => FALSE, 'min_depth' => $parent['depth'] + 1, 'max_depth' => $parent['depth'] + 1, 'conditions' => array('plid' => $parent['mlid'])); echo '<li class="nb' . $children3["link"]["mlid"] . '">'; $alias = drupal_get_path_alias($path); echo '<a href="/drupal7/' . $alias . '">' . $children3["link"]["title"] . '</a>'; echo '</li>'; } echo '</ul>'; echo '</div>'; } else { $alias = drupal_get_path_alias($path); echo '<a href="/drupal7/' . $alias . '">' . $children2["link"]["title"] . '</a>'; } } echo '</ul>'; echo '</div>';
} else { ?> <?php // If level is equal to 3, get and print the parent's name if ($level == 3) { print '<div id="home-tabs-left" class="internal"><div id="menu-left-internal">'; $menuParent = menu_get_active_trail(); //get rid of the last item in the array as it is the current page $menuParentPop = array_pop($menuParent); //Just grab the last item in the array now $menuParent = end($menuParent); //if it is not the home page and it is not an empty array if (!empty($menuParent) && $menuParent['link_path'] != '') { print '<ul><li class="third-level-parent">' . l($menuParent['title'], $menuParent['link_path']) . '</li></ul>'; } $menuItem = menu_link_get_preferred('node/' . $node->nid); print '<ul><li class="active">' . l($menuItem['link_title'], $menuItem['link_path']) . '</li></ul>'; print '</div></div>'; } ?> <?php } ?> <?php /* if(!empty($page["menu_left_level"])){ ?> <div id="home-tabs-left" class="internal"> <div id="menu-left-internal"> <?php print render($page["menu_left_level"]); ?> </div> </div> <?php }*/
function scsmetronic_subtheme_links__system_main_menu($variables) { $action_links = menu_link_get_preferred($_GET['q']); //for getting th eparent link for menu local action. $parent_link = $action_links['tab_parent_href']; $toggler = ''; $modal = theme_get_setting('theme_modal'); $modal_array = explode("\n", $modal); if (isset($variables['links'])) { $sub_menu = FALSE; $links = $variables['links']; $ulclass = 'page-sidebar-menu '; $toggler = '<li><div class="sidebar-toggler hidden-phone"></div></li>'; } else { $sub_menu = TRUE; $links = $variables; $ulclass = 'sub-menu '; } $html = '<ul class="' . $ulclass . '">'; $html .= $toggler; foreach ($links as $key => $link) { if (is_numeric($key)) { $href = $link['#href']; $title = $link['#title']; $liclass = $link['#attributes']['class']; $below = $link['#below']; $linkclass = ''; if (in_array('first', $liclass)) { $linkclass = 'start '; } if (in_array('last', $liclass)) { $linkclass = 'last '; } $selected = ''; if (isset($link['#href']) && ($link['#href'] == current_path() || $link['#href'] == $parent_link)) { $linkclass .= 'active '; $selected = '<span class="selected"></span>'; } $arrow = ''; $check = false; if (!empty($below)) { $arrow = '<span class="arrow "></span>'; if (scsmetronic_check_below($below)) { $linkclass .= 'active '; $selected = '<span class="selected"></span>'; $arrow = '<span class="arrow open"></span>'; } } $icon = ''; if (!$sub_menu) { if (!empty($link['#localized_options']) && !empty($link['#localized_options']['icon'])) { $icon = '<i class="fa ' . $link['#localized_options']['icon'] . '"></i>'; } else { $icon = '<i class="fa fa-arrow-circle-right"></i>'; } } $title = $icon . '<span class="title">' . $title . '</span>' . $selected . $arrow; foreach ($modal_array as $m_array) { $mo_array[] = trim($m_array); } if (in_array($href, $mo_array)) { $output = l($title, $href, array("html" => TRUE, 'attributes' => array("data-toggle" => "modal"))); } else { $output = l($title, $href, array("html" => TRUE)); } if (!empty($below)) { $output = '<a href="javascript:;">' . $title . '</a>'; } $html .= '<li class="' . $linkclass . ' ">' . $output; if (!empty($below)) { $html .= scsmetronic_links__system_main_menu($below); } $html .= '</li>'; } } $html .= '</ul>'; return $html; }
/** * Wraps menu_link_get_preferred(). */ protected function menuLinkGetPreferred($menu_name, $active_path) { return menu_link_get_preferred($active_path, $menu_name); }
/** * Helper function for showing the title and subtitle of a site section in the * highlighted region. * * The description is retrieved from the description of the menu item. */ function _bvng_get_title_data($node_count = NULL, $user = NULL, $req_path = NULL) { $status = drupal_get_http_header("status"); // This way disassociates the taxanavigation voc, is more reasonable, but a bit heavy. // Only 'GBIF Newsroom' has a shorter name in the nav. $source_menu = strpos($req_path, 'user') !== FALSE ? 'user-menu' : 'gbif-menu'; $active_menu_item = menu_link_get_preferred(current_path(), $source_menu); if (strpos(current_path(), 'user') !== FALSE) { switch ($req_path) { case 'user/login': $title = array('name' => t('Login to GBIF'), 'description' => ''); break; case 'user/register': $title = array('name' => t('Register New GBIF Account'), 'description' => t('Please, register to the GBIF data portal for downloading data, or login if you already have an account')); break; case 'user/password': $title = array('name' => t('Request a new password'), 'description' => t('Please enter your username or the registered email address in order to reset your password')); break; case 'node/241': $title = array('name' => t('Thanks for registering!'), 'description' => t('Please verify your email address')); break; default: if (isset($user->uid) && $user->uid !== 0) { $user = user_load($user->uid); $name = ''; $name .= _bvng_get_field_value('user', $user, 'field_firstname'); $name .= ' '; $name .= _bvng_get_field_value('user', $user, 'field_lastname'); $title = array('name' => $name, 'description' => t('User account and personal settings')); } elseif ($status == '403 Forbidden') { $title = array('name' => t('You need to log in to visit this page'), 'description' => t('403 Forbidden: proper permission required')); } elseif (isset($user->uid) && $user->uid == 0) { $title = array('name' => t('Log in to GBIF'), 'description' => ''); } break; } } elseif ($status == '404 Not Found') { $title = array('name' => t("Hmm, the page can't be found"), 'description' => t('404 Not Found')); } elseif ($status == '403 Forbidden') { $title = array('name' => t('You need to log in to visit this page'), 'description' => t('403 Forbidden: proper permission required')); } elseif ($active_menu_item) { // The resource/summary and resources/keyinformation are shared by two menu parents // so we force the title here. if (drupal_match_path($req_path, 'taxonomy/term/764') || drupal_match_path($req_path, 'node/234') || drupal_match_path($req_path, 'resources/archive')) { $title = array('name' => t('Resources'), 'description' => t('Tools and information to support the GBIF community')); } else { $parent = menu_link_load($active_menu_item['plid']); $title = array('mild' => $parent['mlid'], 'name' => $parent['link_title'] == 'GBIF News' ? 'GBIF Newsroom' : $parent['link_title'], 'description' => $parent['options']['attributes']['title']); } } elseif (strpos(current_path(), 'taxonomy/term') !== FALSE) { $term = taxonomy_term_load(arg(2)); $title = array('name' => format_plural($node_count, 'Item tagged with "@term"', 'Items tagged with "@term"', array('@term' => $term->name))); } elseif (strpos(current_path(), 'search') !== FALSE) { $title = array('name' => t('Search GBIF')); } return $title; }
/** * Current Section MLID * * Returns the MLID of the current section (2nd level page). * * @param string $preferred_menu The name of the menu to prefer. * * @return integer The section MLID. */ public static function current_section_mlid($preferred_menu = 'main-menu') { $link = false; $found = array(); // First, check to see if ablecore_menu is enabled and we have a match. if (module_exists('ablecore_menu')) { $link = ablecore_menu_get_preferred_link(); } // Second, see if Drupal will give us one. if ($link === false) { $link = menu_link_get_preferred($_GET['q'], $preferred_menu); } if ($link !== false) { while ($link['plid'] !== "0") { if (in_array($link['plid'], $found)) { break; // Abort loop if a circular reference is detected } else { $found[] = $link['plid']; $link = menu_link_load($link['plid']); } } return $link['mlid']; } else { return false; } }
/** * Local function * * Builds a sidebar menu based on the current path. * * @return HTML content or false * * @todo Refactor */ function _uw_boundless_uw_sidebar_menu() { global $theme; // check the theme setting for visibility if (!theme_get_setting('uw_boundless_sidebar_menu_visibility')) { return FALSE; } // get some data $current_path = current_path(); $active_trail = menu_get_active_trail(); $current_depth = count($active_trail); $active_trail_key = $current_depth - 1; // no trail, no sidebar menu if ($active_trail_key < 1) { return FALSE; } // prevent admin paths from building the sidebar menu if (path_is_admin($current_path)) { return FALSE; } // is menu_name a key in the active trail if (!array_key_exists('menu_name', $active_trail[1])) { return FALSE; } // don't build the sidebar if menu_name is not the main-menu if (!$active_trail[1]['menu_name'] == 'main-menu') { $_message = 'I\'m sorry, there\'s an issue with the sidebar menu. I can\'t build it. The active trail of this page does not appear to be the main-menu. It looks like it\'s using menu "' . $active_trail[1]['menu_name'] . '".'; drupal_set_message($_message, 'warning'); // write to log watchdog_exception($theme, new Exception($_message)); return FALSE; } // get the current menu link $current_link = menu_link_get_preferred($current_path, 'main-menu'); $output = TRUE; $output_menu = ''; $output_menu .= '<ul>'; // only display sidebar menu when there's a parent and it's not hidden if (isset($current_link['plid']) && !$current_link['hidden']) { // first level links if ($current_depth == 2 && $current_link['has_children']) { // show sub tree of current node $output_menu .= '<li class="page_item page_item_has_children current_page_item">'; $output_menu .= l($current_link['link_title'], $current_link['link_path']); // parameters to build the tree $parameters = array('active_trail' => array($current_link['plid']), 'only_active_trail' => FALSE, 'min_depth' => $current_link['depth'] + 1, 'max_depth' => $current_link['depth'] + 1, 'conditions' => array('plid' => $current_link['mlid'])); // get the children $children = menu_build_tree($current_link['menu_name'], $parameters); $output_menu .= '<ul class="children">'; foreach ($children as $child) { if (!$child['link']['hidden']) { $output_menu .= '<li class="page_item">'; $output_menu .= l($child['link']['link_title'], $child['link']['link_path']); $output_menu .= '</li>'; } } $output_menu .= '</ul>'; $output_menu .= '</li>'; } elseif ($current_depth > 2) { // show sub tree of parent and // display current node as current page item // get active parent by moving one up the trail $active_parent = $active_trail[$active_trail_key - 1]; // create flag if parent points home $active_parent_is_front = $active_parent['link_path'] === '<front>' ? TRUE : FALSE; // get the parent menu link $parent_link = menu_link_get_preferred($active_parent['link_path'], 'main-menu'); // however, if active parent points home, create a new array // using front as path if ($active_parent_is_front) { $parent_link = array('link_title' => $active_parent['link_title'], 'link_path' => '<front>', 'plid' => $active_parent['plid'], 'mlid' => $active_parent['mlid'], 'menu_name' => $active_parent['menu_name'], 'depth' => $active_parent['depth']); } $output_menu .= '<li class="page_item page_item_has_children current_page_ancestor current_page_parent">'; $output_menu .= l($parent_link['link_title'], $parent_link['link_path']); // parameters to build the tree $parameters = array('active_trail' => array($parent_link['plid']), 'only_active_trail' => FALSE, 'min_depth' => $parent_link['depth'] + 1, 'max_depth' => $parent_link['depth'] + 1, 'conditions' => array('plid' => $parent_link['mlid'])); // get the children $children = menu_build_tree($parent_link['menu_name'], $parameters); $output_menu .= '<ul class="children">'; foreach ($children as $child) { if (!$child['link']['hidden']) { if ($current_path == $child['link']['link_path']) { $output_menu .= '<li class="page_item current_page_item">'; $output_menu .= '<span>' . $child['link']['link_title'] . '</span>'; if ($child['link']['has_children']) { // get the grandchildren // parameters to build the tree $parameters = array('active_trail' => array($child['link']['plid']), 'only_active_trail' => FALSE, 'min_depth' => $child['link']['depth'] + 1, 'max_depth' => $child['link']['depth'] + 1, 'conditions' => array('plid' => $child['link']['mlid'])); $grandchildren = menu_build_tree($child['link']['menu_name'], $parameters); $output_menu .= '<ul class="children">'; foreach ($grandchildren as $grandchild) { if (!$grandchild['link']['hidden']) { $output_menu .= '<li class="page_item">'; $output_menu .= l($grandchild['link']['link_title'], $grandchild['link']['link_path']); $output_menu .= '</li>'; } } $output_menu .= '</ul>'; } } else { $output_menu .= '<li class="page_item">'; $output_menu .= l($child['link']['link_title'], $child['link']['link_path']); } $output_menu .= '</li>'; } } $output_menu .= '</ul>'; $output_menu .= '</li>'; } else { // link has no children $output = FALSE; } } else { $output = FALSE; } $output_menu .= '</ul>'; return $output ? $output_menu : $output; }
function _sidebar_menu() { $parent = menu_link_get_preferred($_GET['q']); $parameters = array('active_trail' => array($parent['plid']), 'only_active_trail' => FALSE, 'min_depth' => $parent['depth'] + 1, 'max_depth' => $parent['depth'] + 1, 'conditions' => array('plid' => $parent['mlid'])); $children = menu_build_tree($parent['menu_name'], $parameters); return '<ul class="sidebar-menu">' . _process_child_menu_node($children) . '</ul>'; }