Real Name seems to trim some of my longer names fairly short. Is there a way to adjust how Real Name decides how/when to do this?

Comments

nancydru’s picture

On the "General" tab, there is a setting called "Maximum allowed username length." (At least in D6.)

dddbbb’s picture

Can't see a General tab on the D7 version.

dave reid’s picture

It trims to 255 characters. How is that short?

dddbbb’s picture

Status: Closed (fixed) » Active

255 characters sounds like plenty, however this is not what I'm experiencing.

I'm seeing it trim at 15 characters and then an elipsis added to the end. I'm using a first name and last name field on user profiles to determine a user's 'real name' and a maximum of 15 chars just seems way short (most names are being trimmed as a result).

dave reid’s picture

Ah, you are seeing the core theme('username') behavior.

http://api.drupal.org/api/drupal/includes--theme.inc/function/template_p... automatically trims usernames to 15 characters.

dddbbb’s picture

Do you know how I might be able to override this and set it to something higher than 15?

dave reid’s picture

Status: Active » Fixed

The best resource is the documentation handbook on overriding themeable output: http://drupal.org/node/341628

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

liquidcms’s picture

this is ridiculous that core clips usernames like this..

as Dave suggested, in D7 the code to fix this is this.. and goes in your template.php

function mytheme_preprocess_username(&$variables) {
  $account = $variables['account'];

  $variables['extra'] = '';
  if (empty($account->uid)) {
   $variables['uid'] = 0;
   if (theme_get_setting('toggle_comment_user_verification')) {
     $variables['extra'] = ' (' . t('not verified') . ')';
   }
  }
  else {
    $variables['uid'] = (int) $account->uid;
  }

  // Set the name to a formatted name that is safe for printing and
  // that won't break tables by being too long. Keep an unshortened,
  // unsanitized version, in case other preprocess functions want to implement
  // their own shortening logic or add markup. If they do so, they must ensure
  // that $variables['name'] is safe for printing.
  $name = $variables['name_raw'] = format_username($account);
  $variables['name'] = check_plain($name);

  $variables['profile_access'] = user_access('access user profiles');
  $variables['link_attributes'] = array();
  // Populate link path and attributes if appropriate.
  if ($variables['uid'] && $variables['profile_access']) {
    // We are linking to a local user.
    $variables['link_attributes'] = array('title' => t('View user profile.'));
    $variables['link_path'] = 'user/' . $variables['uid'];
  }
  elseif (!empty($account->homepage)) {
    // Like the 'class' attribute, the 'rel' attribute can hold a
    // space-separated set of values, so initialize it as an array to make it
    // easier for other preprocess functions to append to it.
    $variables['link_attributes'] = array('rel' => array('nofollow'));
    $variables['link_path'] = $account->homepage;
    $variables['homepage'] = $account->homepage;
  }
  // We do not want the l() function to check_plain() a second time.
  $variables['link_options']['html'] = TRUE;
  // Set a default class.
  $variables['attributes_array'] = array('class' => array('username'));
}
dddbbb’s picture

Status: Active » Closed (fixed)

@liquidcms Thanks for the suggested fix. I'll give it a try.

gionnibgud’s picture

function mytheme_preprocess_username(&$variables) {
  $variables['name'] = format_username($variables['account']);
}

This was enough.
cheers

radziaziz’s picture

thanks, gionnibgud. Your solution works at least for me.

waverate’s picture

Issue summary: View changes

What's the D8 (8.6.5) equivalent of #11?