My theme goes through the "theme_menu_item_link" function to change the "My account" link title to the username. Is it still possible to do this with the "me" module enabled? It looks like it switches the theme function if it detects the "user/" path.

Comments

cdale’s picture

It should work just fine. 'me' doesn't actually switch the theme function, it just intercepts it, makes a small change to the link item, then passes it on as though me never existed.

Are you experiencing trouble with this? Or did you just look at the code before using it? if you are having trouble, please report back here with as much information as you can. :)

mshaver’s picture

Thanks for the reply. Here is the theme function I'm using that doesn't seem to work once "me" module is activated. This is a zen sub theme if that makes any difference? I moved the "My account" menu item out of the navigation and into a custom menu called "Persistent Links".

function custom_theme_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }

  // Replace 'My Account' link title with a user's username or displayname
  if ($link['menu_name'] == 'menu-persistent-links' && $link['page_callback'] == 'user_view') {
    global $user;
    if ($user->profile_displayname != '') {
      $link['link_title'] = t('Hello, !user', array('!user' => $user->profile_displayname));
      $link['title'] = t('Hello, !user', array('!user' => $user->profile_displayname));
    }
    else {
      $link['link_title'] = t('Hello, !user', array('!user' => $user->name));
      $link['title'] = t('Hello, !user', array('!user' => $user->name));
    }
  }

  return l($link['title'], $link['href'], $link['localized_options']);
}
cdale’s picture

Ahh, I see the problem. :) You need to name the function custom_menu_item_link where "custom" is your themes name. Be sure to clear the theme cache after making that change This is probably easiest done by visiting admin/build/themes.

Does that work for you?

mshaver’s picture

Sorry, I put "custom_theme" as a placeholder. The actual function does use the theme name like so: moblin2_menu_item_link($link).

cdale’s picture

hmmm... As far as I know, it should work. It's a zen sub theme you say? I might quickly make a zen sub theme and see what happens.

cdale’s picture

Well I just made a zen sub theme, and added the custom menu_item_link theme hook, and it gets called alright. Could it possibly be another module that is interfering? I'm assuming you already cleared all your caches. :)

I'd would think it might be another module though, as I have me installed with DHTML menu, which also overrides menu_item_link, and both modules and theme work fine. Me gets called first, which calls the DHTML menu one, which calls the theme layer.

I'm stumped, so any extra information you can provide might prove useful.

mshaver’s picture

Strange? The only module that invoked that function was the admin_menu module and it didn't fix the problem when I disabled it? I haven't upgraded to the latest Zen theme yet, but I doubt that function has changed in the newest? Maybe I should look into this though?

Thanks for your help and I'll keep digging around. :)

cdale’s picture

hmm... I also have admin_menu installed, so I don't think that's the problem. Does the problem still persist if you disable the 'me' module?

cdale’s picture

I don't think there is a problem with 'me' here so closing this issue. Please re-open if the problem still exists.

cdale’s picture

Status: Active » Closed (fixed)