I collect the user's first and last name at registration time and store them (via hook_user) in a custom table (profile.module to general for my needs.)

I'm using the Blue Marine theme and would like to display the full name above the navigation instead of the user (account) name.

Where's the user name string above the navigation stored? (I haven't messed with themes at all--completely focused on functionality until now.)

Also, what's the best way to go about adding the full name to the user object so it's available globally?

Thanks.

Comments

nedjo’s picture

The navigation block is set in user.module in the following line:


           $block['subject'] = $user->uid ? $user->name : t('Navigation');

In your theme, I suppose, you could detect a theme_block() subject that's equal to $user->name and substitute your own data before outputting the block.

Also, what's the best way to go about adding the full name to the user object so it's available globally?


function whatever() {
  global $user;
  // fetch your full name as variable $full_name, then...
  $user->full_name = $full_name;
}

johnhanley’s picture

Yes, the navigation block (duh!)

I need to take a break 'cause that was too obvious.

It's all right there (just like the song, "Downtown") in the user.module.

nedjo, thanks for your help.

johnhanley’s picture

Ok, perhaps it's not as obvious as first thought.

I'm not clear what you mean when you say "In the theme". Are you suggesting to include some logic to change the block subject at the top of xtemplate.xtmpl?

nedjo’s picture

... the output. In this case, the blocks are output by xtemplate.engine's xtemplate_block() function. You could hack it, e.g.,


function xtemplate_block(&$block) {
  global $xtemplate;
  global $user;

  if ($block['subject'] == $user->name) {
    $block['subject'] = $user->full_name;
  }
  ....
}

(All of this is more cleanly done in PHPTemplate, where you can include such logic in templates rather than hacking the engine.)

johnhanley’s picture

Drupal should seriously consider an approach like patTemplate which uses XML-based templates and doesn't contain any server side logic at all.

Nevertheless, your solution will suffice for my present need--thanks!

nedjo’s picture

Drupal supports multiple theme engines--so you could consider writing and contributing one for your preferred system.

johnhanley’s picture

and one that's been raised before.

If you never seen patTemplate in action you're missing out. It's a thing of beauty.

johnhanley’s picture

I'm checking to see if $user->full_name exists before making the change:

  global $user;
  if ($block['subject'] == $user->name && isset($user->fullname)) {
    $block['subject'] = $user->fullname;
  }
johnhanley’s picture

Incidentally, the arg passed to xtemplate_block() is an object and not an array.

As such, the aforementioned lines should be:

  global $user;
  if ($block->subject == $user->name && isset($user->fullname)) {
    $block->subject = $user->fullname;
  }
Mojah’s picture

Hi,

How would this be achieved for phpTemplate?

Love, Live, Laugh

liveoutloud2day’s picture

I would love to do this for phptemplate - anyone know how to do it?

Thanks!

johnhanley’s picture

liveoutloud2day,

I switched to phptemplate many months back and here's how to do the same.

At the top of block.tpl.php add the following php code:

  // start of hack  -- john hanley, 5/31/2006
  // change navigation block subject from default user name to full name (if defined)
  global $user;

  if ($block->subject == $user->name && isset($user->fullname)) {
    $block->subject = $user->fullname;
  }
  // end of hack

The above assumes that the field "fullname" has been added to the $user object, which can be accomplished with hook_user().

johnhanley’s picture

nedjo,

Where do you recommend making the function call that's responsible for loading the $user object with the full name?

Thanks again for all your help.

nedjo’s picture

in the part outside the $may_cache part:


global $user;
if ($may_cache) {

}
else {
  // your handling
}

johnhanley’s picture

Good call, thanks.

vanchisel’s picture

If anyone is looking for a complete solution to replacing the username in the navigation block with fullname here is the code I used. Since I seperated firstname and lastname they should be joined together. Place the code in the block.tpl.php as follows:

<?php
  global $user;
  profile_load_profile($user);
  if ($block->subject == $user->name && isset($user->profile_firstname) && isset($user->profile_lastname)) {
    $block->subject = $user->profile_firstname .' ' .$user->profile_lastname;
  }
?>
<div class="block block-<?php print $block->module; ?>" id="block-<?php print $block->module; ?>-<?php print $block->delta; ?>">
    <?php if ($block->subject) { ?><h2 class="title"> <?php print $block->subject; ?> </h2><?php } ?>
    <?php print $block->content; ?>
</div>

deQuindío Fitness

teejayuu’s picture

This is great I have been trying to do this for a while. Can this work with LDAP integration?

vanchisel’s picture

So, this give me a chance to learn about something knew.

deQuindío Fitness

j2g2’s picture

Hi, may I ask which file should I edit?

Thanks.