By doctorpaul on
Hi everyone
On my test-site it looks like Drupal only displays the first 15 characters of a username.
I have one test user with >15 characters in his name (humpty dumpty was pushed).
In a view (table-style) his name displays shortened as humpty dumpty w...
Even in full node written by him, it appears as humpty dumpty w...
I suspect I have to go and change something in an actual file somewhere? I have around on this site looked for a solution but can't see anything obvious - sorry if this has been asked before but there's a chocolate donut for the first person to find me an answer...
Thanks
Paul
Comments
theme?
It may be an artifact of your theme. Try a different theme and see if you have the same issue. If not, then you've at least narrowed it down.
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide
Thanks Steven I will try
Thanks Steven
I will try that in a bit - (I'm struggling with views now). I am using Garland - the basic theme if that helps anyone else answer the question in the meantime
Paul
If the username is more than
If the username is more than 20 characters it is truncated to 15. This is the default behaviour of http://api.drupal.org/api/function/theme_username/5. You can override it by implementing mytheme_username() in your theme's template.php (suggest you work on a copy of Garland, installed in sites/all/themes and with a new name, rather than the original).
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Thanks for your info gpk.
Thanks for your info gpk. Appreciate it.
I don't fully understand the answer because I don't know how to
- I have much to learn.
But I followed your link and straight away noticed this line of comment in the code:
I wondered what the reasoning was and now this may confirm that it's not just Drupal being niggly. Does anyone know if this is a real problem? Perhaps I'm just better off leaving things as they are. After all: 15 letters will be enough for most people...
It's probably talking about
It's probably talking about the user admin pages, but since you can leave Garland as the theme for the admin section you can safely increase this limit in your own theme or own version of Garland.
>I don't fully understand the answer
1. Copy the garland folder from the main themes directory in your drupal installation to sites/all/themes, and call the new folder garland_custom.
2. At the bottom of the file template.php in the garland_custom folder, add the following (without the opening and closing PHP tags):
Then change the values 15 and 20 to whatever you want. Note you could also call this function garland_custom_username(), I won't dwell on that now, won't make any practical different to you ...
3. Enable the new theme from your admin interface and optionally choose a theme to use for the admin pages by visiting admin/settings/admin.
BTW there is meant to be a space before the lines that begin with *. Not important but makes the code neater (that's the standard Drupal comment style...)
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Nice
Thanks for the clear step-by-step stuff gpk. Much appreciated from this new person.
I post this into my
I post this into my templates.php file for my currently enabled theme, and it returns this error:
Fatal error: Cannot redeclare theme_username() (previously declared in /home5/greypage/public_html/includes/theme.inc:1593) in /home5/greypage/public_html/sites/nm.greypages.us/themes/aboutpeople/template.php on line 220
Indeed, when copying
Indeed, when copying theme_username() into template.php it needs to be renamed to themename_username() [or possibly phptemplate_username(), but this is not recommended for D6+].
gpk
----
www.alexoria.co.uk
_
I attempted to do this in my theme and only got a blank white screen after uploading the modified template.php file. I'm running Drupal 6, and I believe this was posted for Drupal 5, but it should still work if the API page is correct. Any thoughts?
Yes should still work though
Yes should still work though for D6 the preferred name for the function would probably be themename_username() where themename is the name of your theme.
If wanting to modify an existing core or contrib theme in this way then that could be done by declaring a subtheme (http://drupal.org/node/225125) rather than copying the original and modifying the copy.
gpk
----
www.alexoria.co.uk
Still not working...
I've added the following to the bottom of my template.php file. I'm using the
themename_username()format. The name of my theme is litehouse. I'm getting a blank page when I load anything that uses the theme.Have you tested this on a Drupal 6 site or what it for Drupal 5? I think Drupal 6 doesn't like it. :(
Thanks for this step..
Thanks for this step..
Table in themes or database ?
Hi,
I am having the same need. My site is a Market Place and my sellers always wanna add extension such as : Corp., Company, Team, Friends, ...etc.
When they register, there is no limit, so they wonder why they name is always trunk ?
I noticed that the full view of the user shows the full name. However, I can't show the full name with views ?? Is it a View issue or theme issue ? (same problem with Garland or Fusion).
I don't think this will affect databases tables as they are already recording full names... so, why making this trimmed with PHP for all other views ?
In my point of view, this is extra code, useless as long as users want to be named as they suggested. Also, for SEOs, this makes it weak in a user point of view : "How can I be recognized by SEOs if my name is trunk ?"
Useless also because we can choose to restrict size limit in the Access Rules section.
Really, I don't understand this limit...
I am having the same issue in Drupal 7
Hi,
I am experiencing the same issue in Drupal 7. Can anyone help me please? The code above doesn't work.
The username appears fine in their account page but not in a View. I would like the full user name to be displayed.
Thanks in advance!
Same dillemma
I'm also running into the same issue, and can't quite figure out a fix.
REALNAME MODULE
My solution was to use the realname module.
Configure it with whatever replacement pattern you want.
In VIEWS you'll now be able to add the "real name" field, with an untrucated user name!
I had the same issue.
I had the same issue. RealName module resolved it. However, I am not sure what is the safe maximum length without breaking the table. I use D6
You can try to put this into
You can try to put this into your template.php. Works for me in Drupal 7
Use preprocess_username() in template.php
Bit late to this very old thread, but probably best do the override in the theme layer with _preprocess_username() (lines 19 & 20 are where you can alter the values):
function yourthemename_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);
if (drupal_strlen($name) > 35) {
$name = drupal_substr($name, 0, 30) . '...';
}
$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',
),
);
}