I’m trying to print a drupal menu outside drupal. In order to achieve this I ran the bootstrap as follows:
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
And I render my menu as follows:
public static function getDrupalMenu($menuName) { $menu_output = &drupal_static(__FUNCTION__, array()); if (!isset($menu_output[$menuName])) { $tree = menu_tree_all_data($menuName); $menu_output[$menuName] = menu_tree_output($tree); } return render($menu_output[$menuName]); }
Which is basically just a copy of the menu_tree
function AND with menu_tree_all_data instead of menu_tree_page_data so I get all links no matter what page I’m on.
Everything works fine so far, my menu is printed, everybody is happy… but unfortunately my links are incorrect somehow. To solve this I’ve used a solution for absolute links as described here:
How to force absolute links on a menu tree in Drupal 7
So I use:
function mythemename_menu_link(array $variables) { $element = $variables['element']; $sub_menu = ''; if ($element['#below']) { $sub_menu = drupal_render($element['#below']); } $output = l($element['#title'], $element['#href'], array_merge($element['#localized_options'], array('absolute' => TRUE))); return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>n"; }
This works fine on my drupal site, but where I call the getDrupalMenu() after initializing the bootstrap it does not work (empty result, not even the original one). I probably have to set the theme or something, but I can’t find what or where to do so.
Just to be clear: when I change the code in core (menu.inc) is works fine on both sites… it just gives en empty result when I override it in the theme.
Any pointers or solutions ?
Sponsored by SupremePR