It would be nice to expose some services on the menu system. I have used the attached patch for communicating the menu structure to a flash menu component.

This services patch exposes the three main menu system functions: menu_primary_links(), menu_secondary_links() and menu_get_menu(). Moreover, it implements a new function menu_service_get_visible_menu, which returns the full recursive menu system structure.

CommentFileSizeAuthor
menu_service.zip2.98 KBebababi

Comments

idflood’s picture

This menu service has been a great help for me. However, I had bad "href" returned (ex: "node/24" and not the path i had given like "about").

I had to add this line in the last loop to make the href reflect the alias of the menu:
$links[$index]['href'] = ( drupal_get_path_alias($links[$index]['href'])) ? drupal_get_path_alias($links[$index]['href']) : $links[$index]['href'];

######

foreach ($menu['visible'][$pid]['children'] as $cid) {
      $index = "menu-$start_level-$count-$pid";
      if (menu_in_active_trail_in_submenu($cid, $pid)) {
        $index .= "-active";
      }
      $links[$index] = menu_item_link($cid, FALSE);
+      $links[$index]['href'] = ( drupal_get_path_alias($links[$index]['href'])) ? drupal_get_path_alias($links[$index]['href']) : $links[$index]['href'];
      
      $children = menu_service_get_visible_menu(1, $cid);
      $links[$index]['children'] = $children;
      $count++;
    }
ebababi’s picture

Status: Needs review » Active

devertex, thank you for your constructive comments.

The reason I haven't use the path aliases was to implement the function "compatible" with the Drupal's menu system functions. For the purpose of path aliasing I have created this module.

Probably, the best way is to introduce a new parameter to indicate the return of aliased results.

brendoncrawford’s picture

Here is a similar patch/module for Drupal 6.

http://drupal.org/node/301259

brmassa’s picture

Status: Active » Closed (duplicate)

guys, its a duplicate issue from http://drupal.org/node/140282 (which patch was already applied)

rpx’s picture

Is there a way for menu.PrimaryLinks to return the sub-menu items as well?

For example, if my Primary Menu is ...
Home
About Us
-- Who we are
-- How to contact us
Our Services

.. then, when I run the menu.PrimaryLinks service, I only see Home, About Us, and Our Services. The two sub items (Who we are, and How to contact us) do not show up in what is returned.

Perhaps I am doing something wrong. Unsure. Any thoughts?