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

Bilmar’s picture

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?

rburgundy’s picture

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?

  $firstname = $content_profile->get_variable('uprofile', 'field_firstname');
  $firstname = $firstname[0]['value'];
  print $firstname;
Bilmar’s picture

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.

safetypin’s picture

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;
}
YK85’s picture

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

honorfield’s picture

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

rjbrown99’s picture

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

doublejosh’s picture

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.

int_ua’s picture

What about profile_load_profile function?

int_ua’s picture

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

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%