i18n breadcrumbs and nested menus

I recently tried to add breadcrumbs to one of our client sites. We wanted breadcrumbs to reflect the location of the current page in the nested menu system. The usual Drupal breadcrumb functions failed utterly, returning bizarre values for the supposed menu items in the current trail. (Things like a negative int where one expects a positive value in a string.) The site uses both i18n (internationalization) and nice menus. I assumed one or both of these was the problem. I also decided that troubleshooting it was more trouble than it was worth, so I whipped up this function instead. It finds the current item in the menu tree and iterates through its parents until it hits the top. It then turns that list of menu items into breadcrumbs. Note that I pop off the topmost menu item because in this case it is always "Primary Links" -- more complicated menuing systems might want to test for some value there first.  function transfair_breadcrumbs() { $trail = array(); $alias = drupal_get_path_alias($_GET['q']); list($lang, $path) = split('/',$alias); $menu_tree = menu_get_menu(); $menus = $menu_tree['visible']; // find the current menu item foreach ( $menus as $mid=>$menu ) { if ( $menu['path'] == $path ) { break; } } // build trail while ( !empty($menus[$mid]['pid']) ) { $pid = $menus[$mid]['pid']; $mid = $pid; $trail[] = l( t($menus[$pid]['title']), $menus[$pid]['path'] ); } // clean up array_pop($trail); //remove "Primary Links" if ( !empty($trail) ) { $trail[] = l( t( 'Home' ), 'node' ); $trail = array_reverse($trail); return theme_breadcrumb($trail); } }


Section: 


Topic: 


Add new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.