I am a university webmaster and long time PHP developer who's just getting started with Drupal. We are currently experimenting with, and plan to roll out Drupal as our campus-wide CMS offering sometime in the coming months.

I am trying to build a Drupal theme to match our standard web template. I've mostly gotten it working, but I am having one problem with regard to primary links.

Our template has a primary links section that is displayed as a unordered list. It is designed to display up to two levels of links. Most of the sites that use it display all of their second-level links on all pages, similar to the way the list in the primary links block in rendered. Unfortunately our template has some weird stuff in it with regard to how the primary links are rendered (I did not design it and a redesign is out of the question at this point in time). Basically, in order to get my theme to look right, I need to set an id on the ul tag, insert a class or two on several of the li tags, and insert an empty li at the end of the list.

I'm not above hacking away at $block->content in block-menu-primary-links.tpl.php to get the list looking as I'd like (I think SimpleXML would work well here), but that seems way too kludgy and inefficient. Is there some way that I can access the entire primary links tree, either as a single data structure or through some kind of recursive function calls, so that I can generate my own list of links? It has to be possible because $block->content is getting its list from somewhere, but I can't seem to figure out where that is.

I know I can get an array of the top-level primary links from $primary_links and a similar array of the secondary pages of the current node from $secondary_links, but I'm looking for a way to get the secondary links of every top-level primary link. I've spent the day searching the API with no luck. Any help is appreciated.

Thanks in advance.

--Jason

Comments

alexey.shponarsky’s picture

This question is as relevant to me!

mooffie’s picture

Is there some way that I can access the entire primary links tree

Yes. Call menu_tree_page_data(). It returns a nested PHP array. It's the tree you're looking for.

Normally --e.g., when menus are shown inside blocks-- this PHP array is converted to HTML by menu_tree_output(). But in case of 'primary/secondary navigation links', this nested array is handed to menu_navigation_links(), which extracts from it links at a certain "level" only. (However, since you're interested in the whole menu structure, and not in just one "level" of links in it, you want to treat that menu as a normal menu, not as 'primary navigation links').