3

I am pretty clueless on how drupal handles such things and I can't seem to grasp the context.

I want a menu link to user/%/edit (using menu token already). But as it seems /edit is a 'tab' item of the user/% menu (also saw it in the db). Using theming I have visually removed the unwanted tabs and I've also merged the user/edit form with the profile2 forms I need for extra fields using form_alter.

The problem is that even though I have a menu link called "My Account" linking to user/%/edit, whenever I click it to go there, the "Edit" menu link appears as active in my main menu instead of the "My Account".

Is there any way to remedy this?

If the question is not clear I will revise it cause it's a pretty confusing issue.

EDIT: to avoid similar answers, the problem is not how to visually remove the tabs, the problem is how to somehow alter or ignore the user/* menu structure so the "Edit" part is not a separate tab anymore and thus it won't show when I click the link that leads to to user/%/edit

1
  • I have hidden the tabs in page preprocess so I wouldn't mind if edit appearead as active as long as it was hidden. No, the buggy part is that the current tab's name (Edit in this case) shows up as a link (furthermore the current selected link) in the Main Menu instead of my link (which is also there but not active).
    – user5005
    Apr 6, 2012 at 11:22

4 Answers 4

3

Those that will stumble upon this looking for a way to do this without coding and using existing modules try using:

  1. The Tab Tamer module to remove the account 'edit' tab. It is an administration utility that provides easy re-ordering, hiding, and deactivation of tabs and subtabs. You can also rename tab labels.

  2. The Menu Token module to move the account edit menu item to any other menu. This module provides tokens, that could be used in title or in path of menu items (links). For example, if you create menu item with path: "user/[current-user:uid]/edit", the url will be changed "on fly" to: "user/1/edit" (assuming you are user 1).

5
  • Tab Tamer does not allow me any action on user/%/edit tab.
    – user5005
    Apr 6, 2012 at 14:06
  • Ok I see it's a bug that I was able to bypass but still this does not solve the issue. The menu item I've created using Menu Token leads me to user/% with the /edit tab preselected. What I need is to kill all this tab-behaviour and have a link that will link to user/%/edit. Just that. No tabs.
    – user5005
    Apr 6, 2012 at 14:16
  • 1
    Interesting. I recommended this method only in theory. I just tried it out and it appears that the tab tamer module is extremely buggy at this time. So I guess until that module pulls up it's socks, you will have to remove the edit tab using drupal.org/node/68792 and then just use the [current-user:edit-url] token for the menu, which seems to work just fine.
    – user842
    Apr 6, 2012 at 14:45
  • Unfortunately, I have a similar function that does just that, but only removes the tabs "visually" so to speak. The menu structure remains so if I click the menu link that uses the token to lead to user/%/edit, an extra item appears on the menu, labeled "Edit". Same happens if I navigate manually to the URL of one of the other tabs that I've unset, their respective tab titles appear as extra menu items.
    – user5005
    Apr 9, 2012 at 7:12
  • @user842, Tab Tammer module works for me. But, it removes secondary tabs from administration menu also.
    – Pupil
    Jun 12, 2013 at 4:14
3

You want to alter the original menu item that was defined in user.module's hook_menu(). You can do this in hook_menu_alter().

The item's array key is simply the path, so:

function hook_menu_alter(&$items) {
  $items['user/%/edit'] = array(
    'type' => MENU_LOCAL_TASK,
    'page callback' => 'my_custom_page_callback',
    'page arguments' => array(1),
    'access callback' => TRUE,
  ),
}
7
  • 1
    This is pretty good, but I think the issue doesn't lie in the page destination, but the active trail being set differently as to how OP wants it. Great example though!
    – Chapabu
    Apr 6, 2012 at 10:30
  • Then he simply needs to set the 'type' in the code above to whatever he wants, such as MENU_CALLBACK. That's how the local tasks (tabs) are managed. Apr 6, 2012 at 11:07
  • OR he should just unset the menu item altogether. But the answer to changing the default behavior completely lies in hook_menu_alter(). Apr 6, 2012 at 11:08
  • I've started playing with hook_menu_alter meanwhile, merely setting MENU_CALLBACK doesn't seem to do the trick but I am working on it. I'll come back to you if I manage something.
    – user5005
    Apr 6, 2012 at 11:18
  • Try setting the 'title' attribute to change the breadcrumb / active trail. Apr 6, 2012 at 11:38
0

If I understand correctly, you might be able to utilise menu_tree_set_path() in a custom module.

EDIT:

It look like the Menu Trail By Path module might do what you want to long as the path is correct! It utilises menu_tree_set_path() and takes all the legwork out for you!

3
  • If this is right then let me know and I'll expand the answer with an example.
    – Chapabu
    Apr 6, 2012 at 9:26
  • that's not a hook, right? how can I use it? within another hook?
    – user5005
    Apr 6, 2012 at 9:57
  • ooh...what point version of D7 are you using. I think prior do Drupal 7.9, this function did pretty much bugger all -_-
    – Chapabu
    Apr 6, 2012 at 10:33
0

Ok guys figured it out. The 'bug' part was cause I was using Menu Position for various reasons including this portion of the sub-menu and it had a settings tab that I didn't notice before.

Switching from "Insert the current page's title into the menu tree" - which caused the "Edit" to get inserted - to "Mark the rule's parent menu item as being "active"" fixed it all for me.

Other than that I just had to use menu token as usual to create the actual url to the edit page. But all the fuss was because of that one wrong setting, thanks for your time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.