By wd_dominic on
A drupal 6.x question,
What I need to do is incredibly simple:
Get the $mid of the current/active menu item.
I've searched for hours but cannot find anything.
Guys, is there a way?
A drupal 6.x question,
What I need to do is incredibly simple:
Get the $mid of the current/active menu item.
I've searched for hours but cannot find anything.
Guys, is there a way?
Comments
I haven't seen any mid field
I haven't seen any mid field on any menu table
what do you mean with mid?
What don't you explain why
What don't you explain why you want to do this, and maybe we can give you an alternate solution.
Contact me to contract me for D7 -> D10/11 migrations.
up
menu_get_active_trail() do the job for you :
:)
mlid doesn't appear in the
mlid doesn't appear in the array returned by menu_get_active_trail.
Are you sure?
Are you sure about that? I just checked the output of menu_get_active_trail() in D7 and it does contain both mlid and plid. So I believe this is the right way to go. antoine.lucas, your suggestion has been very helpful. Thank you!
mlid and translated menu title
I love Drupal, but I really really hate the menu system, its a pain to work with. Maybe there is a nicer way to do this but I don't just need the mlid, but the translated title of the menu (yeah, thats fun). Here is what I came up with:
Basically you could change that to
to get the mlid.
I'm not sure though if link_path = $item['href'] will always work, like on view paths an stuff, but if the menu item just links to a normal page it should do the trick. Let me know if you have anything better....
$mid of current menu item
I hate the Drupal's menu system too. I'm trying to do this very similar way as you do, but I don't get that menu_get_item() thing. I thought it's enough to use $_GET['q'] to get the current node's path. But there's one problem with this method: I believe it won't work as expected in the case one node appears in your menu multiple times. This is the case of site I'm currently developing and I didn't find the workaround yet.
The problem I see with
The problem I see with $_GET['q'] is that the link_path column in the menu_link table contains raw paths like node/3. $_GET['q'] could be an url alias and therefore you wouldn't find a match. I used menu_get_item() for the translation of the url alias to the raw url.
I'm not sure what you want to do, but if you have multiple items the query should find the entries and you could iterate over the mids, load the full entires and match those against additional conditions. That way you should be able to find the entry you want.
This gives the unaliased
This gives the unaliased path:
$path = drupal_get_normal_path($_GET['q']);Contact me to contract me for D7 -> D10/11 migrations.