Adding a menu item

barry - December 16, 2008 - 07:19

Hi,

I've spent a couple of hours trying to get my head around the menu system and haven't had much luck so far. I've installed content_profile and would like to add an "Edit Profile" link to the Navigation menu that will take the logged in user to the edit page for their profile node.

I'm assuming the proper way to do this is to create an extra module which contains a module_menu() function and add the link within that. I think I may have tried every possible thing that I can think of, with my most sucessful attempt breaking all node edit forms until I removed it.

Can anyone point me in the right direction on this one?

Thanks :)

What does the path for a

gpk - December 16, 2008 - 11:44

What does the path for a typical edit profile page look like?

gpk
----
www.alexoria.co.uk

The content_profile module

barry - December 16, 2008 - 12:06

The content_profile module stores the profiles as nodes, so it's in the node/%nodeid/edit format.

Thanks

So presumably when you are

gpk - December 16, 2008 - 15:16

So presumably when you are on your own account page the edit profile link appears as an additional tab? Does the link have the node/... path or is it of the form user/...? If the former I don't see how it would appear automagically in the tabs, unless force-added by content_profile.module. And when you are on that profile edit page, are is the normal "view" (user account details) tab visible and linked to user/xxx?

Is the user/xxx/edit path still present in any way? What happens if you go there?

Sorry for all the questions but I don't have this module installed!

[update: if the suggestion below works then don't bother answering these Q's!]

gpk
----
www.alexoria.co.uk

The smart way of doing this

gpk - December 16, 2008 - 15:27

The smart way of doing this would be to use http://api.drupal.org/api/function/hook_menu_alter/6 to modify the entry for 'node/%node/edit' in http://api.drupal.org/api/function/node_menu/6, firstly so that 'type' => MENU_LOCAL_TASK || MENU_NORMAL_ITEM so that it has a chance of appearing in a menu tree, and then you'd need to define how the link for this item is to be rendered using a 'to_arg' function (basically the problem is that Drupal needs to know what to put in place of the %node ... for a given user this should be visible on every page but will always the same.

The answer is perhaps to define function node_to_arg($arg) {} in your own module. This needs to return a string (an integer may also work) containing the node id of the current user's profile page/node. There must be a function in content_profile.module which works this out for you.

See also http://drupal.org/node/109153. I'm kind of assuming my logic is correct but have not tried this particular combination. Also the link at the bottom of http://drupal.org/node/109153 suggests another approach using http://api.drupal.org/api/function/menu_link_save. Actually thinking about it that might be necessary since otherwise the Edit tab for all nodes will link to the profile edit page!!!

A less smart but possibly simpler and more flexible way would be to define a new NORMAL menu item at something like user/edit and then in the callback for that menu item just drupal_goto('node/xxx/edit') where xxx is the node number.

gpk
----
www.alexoria.co.uk

Hi, It works :) I opted for

barry - December 17, 2008 - 07:02

Hi,

It works :)

I opted for the not so smart option that you offered and after a few attempts I've managed to get a working menu link, many thanks for your help. I think I'll look into the first option and consider offering a patch for content_profile since after looking through the issues queue for the module a few people have had the same problem.

Thanks Again,

Barry

Great stuff, I think the

gpk - December 17, 2008 - 11:37

Great stuff, I think the menu_link_save() approach might be the best bet for content_profile.module.

gpk
----
www.alexoria.co.uk

 
 

Drupal is a registered trademark of Dries Buytaert.