Probably it’s a simple problem – but though I searched in the forums for hours I didn’t find a solution that works for me. So I ask for help:
I want to build a dynamic menu in Drupal 5 in which I want to display menu items for some particular nodes (witch I calculate depending on the taxonomy system).
In my module I tried to insert a menu item with:
$items[] = array(
'path' => 'node/15',
'title' => $title,
'type' => MENU_NORMAL_ITEM,
'access' => TRUE
);
But this menu item isn’t shown in any menu! And even if it would be shown I am not able to determine where (in which menu and at which position) it would be shown, because this is determined by the ‘path’, which is 'node/15' instead of 'navigation/itemname'.
So I tried to do it with:
$items[] = array(
'path' => 'navigation/itemname',
'title' => $title,
'callback' => 'drupal_goto',
'callback arguments' => array('node/15'),
'type' => MENU_NORMAL_ITEM,
'access' => TRUE
);
Now the menu item is shown in the menu ‘navigation’ and if I click on this menu item the right node is called. But this is true only if the menu item is at the first level. If it is deeper in hierarchy the menu does not open and the menu item isn’t shown as active. Well I think, this might be ok, because the node which is shown is 'node/15' while the menu path is 'navigation/itemname'. So there is no reason to activate the menu.
So I tried to tell Drupal that 'navigation/itemname' is the active item by adding to the hook_nodeapi:
case 'view':
menu_set_active_item('navigation/itemname');
break;
Result: The menu opens and the menu item is active. But now Drupal does not know any more that the shown node is 'node/15' and so the tabs ‘view’ and ‘edit’ aren’t shown any more.
Well, now I am at my wits’ end and hoping someone can tell me what I’m doing wrong. Many thanks in advance!
Comments
My suggestion is to keep a
My suggestion is to keep a table that has the path to each node that you want to create dynamically. Try to keep some flag to identify which node (or user or role or even permission) need that menu to be called dynamically.
Then query the that table and create menu dynamically. You can even use this method for forms.
I think this idea should work and this is what you are looking for.
Hope this will help.
Cheers.
Great Idea
Thank you very much for this proposal. This sounds great and I'm trying to implement it.
But - perhaps I am a little stupid - I do not get, how I have to specify the 'nodepath' in your proposal. If I call it 'node/15' I get the problems described in my first posting.
If I call it 'navigation/node/15' or 'navigation/itemname/node/15' the menu entry is shown but not beeing the active one. And clicking on the menu entry results a 'page not found'.
So what am I doing wrong? How do I have to specify the 'nodepath'?
On submitting the
On submitting the node,
$formurl = url($_GET['q'],NULL,NULL,TRUE);
will get you the full url path, There is a function call for getting the url(i think its drupal_get_path or something like that), with that function save the path to the table as the node path. This path is substituted when the menu called dynamically.
Hope this will help
Cheers.
I think it's
I think it's drupal_get_destination() what you meant.
But this function returns 'node/15' (which is he content of $_GET['q'] too). So we are back at the beginning.
What do I have to do to get a menu item with the menu path 'navigation/itemname' which calls the real path 'node/15' ?
Start from basic.... I need
Start from basic.... "I need to reach a node from menu"...
From start
While i save the (content what ever), i save the link to the node along with a description about the node or a status that is used to identify which node is to created dynamically(Placed correctly at the menu). So now i have a node in my custom table say my_dyn_node.
Now from the example above(i made a mistake)
Here $newgrpid is the status or the condition that identify that this node belong to this node(That condition you need to figure it out, i have no clue what you are trying to do.).
'path' => $object->nodepath, This is the path to your node $object->nodepath is the path that you have saved in the table. This will link you to your node.(here is the place i made mistake last time, i didn't check my comment correctly sorry).
'callback arguments' => array(Your_function), function to what ever you like to do.
Hope this will help.
Cheers.
But how do I manage the two paths?
Thanks for your reply and sorry for the delay (was a few days off).
I understand this as a fine solution. But the only thing I do not get is:
- When I retrieve the node and store it to the database I get (and store) $object->nodepath = 'node/15'.
- But I want this menu item show up in the menu as 'navigation/itemname'.
How can I tell the menu to show up at 'navigation/itemname' and call 'node/15' without getting the problems described in my first posting?
I think you can use path
I think you can use path alias module to convert node to navigation and pathauto module to convert 15 to itemname(node name). Do some research on them.
Hope this will work.
Cheers.
...
Go to admin/build/menu and find out where it ended up.
You can explicitly tell Drupal where to put it initially by doing e.g.
'pid' => 1.(I assume you know you need to clear the cache while dealing with the menu.)
...
Thanks for your reply and sorry for the delay (was a few days off).
Well, it's a dynamic menu. So it does not show up in the admin/build/menu and it is not cached.
Entering the pid does not work. The menu item I want to enter is a node. And so it’s in the menu already as a MENU_LOCAL_TASK, which is displayed as a tab. So the new item for 'node/15' I want to enter is deleted in the _menu_append_contextual_items() (because it's already there as a tab) and not put into the left-side menu bar.