Download & Extend

Theme username as content profile first name

Project:Content Profile
Version:6.x-1.x-dev
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Hello,

Thank you for this great module. I have been able to customize it greatly to be unique for my website!

I was wondering if it is possible to theme username to show as my content profile's first name field throughout the website?
I would appreciate any pointers or support.

Thank you

Comments

#1

I'm still having trouble with the above and would appreciate any pointers.

I'm using Email Registration Module so username is hidden at registration and automatically set to the characters before the @ in the email address (making username not usable in situations where username is used). I would like to therefore have the cck/content profile firstname field show instead when other modules call username (modules such as privatemsg).

Is this something possible?

#2

Attempted code from http://drupal.org/node/316009#comment-1189756 into theme_username but crashed my site.
Can't seen to find any information to set the theme_username to always be the content profile first name field.
Any suggestions?

<?php
  $firstname
= $content_profile->get_variable('uprofile', 'field_firstname');
 
$firstname = $firstname[0]['value'];
  print
$firstname;
?>

#3

I unfortunately wasn't able to figure it out.
Using http://drupal.org/project/realname at the moment until I can get better direction from someone in the community.

#4

I'm not sure if this is the best way to do it, I got this code originally from someone else on this site, but I can't seem to find it at the moment. Modified to display the title of the content profile as a link to the user profile:

This seems to work for v1.0 (not dev). All I need to figure out now is how to modify the user profile page title.

function phptemplate_username($object, $link = TRUE) {
  if ( $object->uid && function_exists('content_profile_load') ) {
    $content_profile = content_profile_load('profile', $object->uid);
  }

  if ( $content_profile ) {
    $name = $content_profile->title;

    if ( $link && user_access('access user profiles')) {
      return l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
    }
    else {
      return check_plain($name);
    }
  }

  // Profile field not set, default to standard behaviour
  if ($object->uid && $object->name) {
    // Shorten the name when it is too long or it will break many tables.
    if (drupal_strlen($object->name) > 20) {
      $name = drupal_substr($object->name, 0, 15) .'...';
    }
    else {
      $name = $object->name;
    }

    if ( $link && user_access('access user profiles')) {
      $output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
    }
    else {
      $output = check_plain($name);
    }
  }
  else if ($object->name) {
    // Sometimes modules display content composed by people who are
    // not registered members of the site (e.g. mailing list or news
    // aggregator modules). This clause enables modules to display
    // the true author of the content.
    if ($object->homepage) {
      $output = l($object->name, $object->homepage);
    }
    else {
      $output = check_plain($object->name);
    }

    $output .= ' ('. t('not verified') .')';
  }
  else {
    $output = variable_get('anonymous', 'Anonymous');
  }

  return $output;
}

#5

subscribing - would anyone familiar with programming be able to comment on code at #4?
Thanks!

#6

Try this one here, it might be a solution for your problem: http://drupal.org/node/285367

#7

One suggestion for #4 - implement cache_get and cache_set. Otherwise you are running a node_load constantly to pull up the profile fields.

#8

This is lovely, but it also seems to have caused an issue in forums for me. A valid author can't be found.

Seems odd since this is a theme layer change not effecting usernames on user objects.

#9

What about profile_load_profile function?

#10

I've succeeded with the following code in template.php without activating Content Profile module:

<?php
function themename_username($object) {
  if (
$object->uid && function_exists('profile_load_profile') ) {
   
profile_load_profile(&$object);
  }
 
  if ( !empty(
$object->profile_name) ) {
   
$name = $object->profile_name;
    if (
user_access('access user profiles')) {
      return
l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
    }
    else {
      return
check_plain($name);
    }
  }

 
// Profile field not set, default to standard behaviour
... %rest of the function, copied from theme.inc%

?>
nobody click here