Skip to main content
Wrong answer
Source Link
Interlated
  • 1.4k
  • 9
  • 21

Since you are using 'special menu items' already, this looks likeCopy the existing special_menu_items module. e.g. welcome_menu_items and put it createsin your menu items alreadycustom modules directory. All you want to doIt is edit the menu 'title'. hook_menu_alter will do thisonly 200 lines, so maintenance particularly if your requirements don't change should not be large.

  1. Create your 3 module files. welcomemenu.module, welcomemenu.info, welcomemenu.install and copy from another module to fill out the .info and .install files.
  2. Create a function as follows:

Assuming welcomemenu moduleChange this code adding '. check_plain($user->name);'.

function welcomemenu_menu_alter(&$items) {case '<nolink>':
  // Add comments$tag to= thevariable_get('special_menu_items_nolink_tag', description'<span>');
 for admin/content.
  global$title $user;
= $variables['options']['html'] $items['node/1623']['title']? =$variables['text'] 'Administer: 'check_plain($variables['text']) . check_plain($user->name);
}    $variables['options']['attributes']['class'][] = 'nolink';
    break;

Clear menu cacheThis will only give you the username, not the full name. You need to ensureedit the profile to provide a full name. You might also want to check that $variables['text'] contains the menus are rebuiltwork 'Welcome' before altering it.

You could debug $variables['text'] and submit a patch if there is a problem with this as noted by Clive.

Since you are using 'special menu items' already, this looks like it creates your menu items already. All you want to do is edit the menu 'title'. hook_menu_alter will do this.

  1. Create your 3 module files. welcomemenu.module, welcomemenu.info, welcomemenu.install and copy from another module to fill out the .info and .install files.
  2. Create a function as follows:

Assuming welcomemenu module.

function welcomemenu_menu_alter(&$items) {
  // Add comments to the description for admin/content.
  global $user;
  $items['node/1623']['title'] = 'Administer ' . check_plain($user->name);
}

Clear menu cache to ensure that the menus are rebuilt.

Copy the existing special_menu_items module. e.g. welcome_menu_items and put it in your custom modules directory. It is only 200 lines, so maintenance particularly if your requirements don't change should not be large.

Change this code adding '. check_plain($user->name);'.

  case '<nolink>':
    $tag = variable_get('special_menu_items_nolink_tag', '<span>');
    $title = $variables['options']['html'] ? $variables['text'] : check_plain($variables['text']) . check_plain($user->name);
    $variables['options']['attributes']['class'][] = 'nolink';
    break;

This will only give you the username, not the full name. You need to edit the profile to provide a full name. You might also want to check that $variables['text'] contains the work 'Welcome' before altering it.

You could debug $variables['text'] and submit a patch if there is a problem with this as noted by Clive.

Source Link
Interlated
  • 1.4k
  • 9
  • 21

Since you are using 'special menu items' already, this looks like it creates your menu items already. All you want to do is edit the menu 'title'. hook_menu_alter will do this.

  1. Create your 3 module files. welcomemenu.module, welcomemenu.info, welcomemenu.install and copy from another module to fill out the .info and .install files.
  2. Create a function as follows:

Assuming welcomemenu module.

function welcomemenu_menu_alter(&$items) {
  // Add comments to the description for admin/content.
  global $user;
  $items['node/1623']['title'] = 'Administer ' . check_plain($user->name);
}

Clear menu cache to ensure that the menus are rebuilt.