By dmetzcher on
Some of my users' usernames are being trimmed (with ellipses) in blocks and views.
I noticed that the new users block that comes with Drupal core does this, and I also noticed that any view (Views 2 module) that I create where the field "User: Name" is used does it as well. I'm having trouble understanding why this is even happening and it seems to have something to do with the fact that the first name (my users' usernames are two words, always) is rather long.
What makes this happen?
...and how can I stop it from happening?
Comments
_
A different set of keywords turned up the following in search.
http://drupal.org/node/243224
Seems like the link above explains this issue and how to correct it in the theme. Unfortunately, the fix provided did not work. Can anyone else provide a way to increase the number of characters before the username will be truncated?
The solution provided in
The solution provided in http://drupal.org/node/243224 will work. Basically you have to do the following -
1. In your theme's template.php file write the function themename_username($object). So if you are using the garland theme the function name will be garland_username.
2. Go to http://api.drupal.org/api/function/theme_username and copy the content of the theme_username function as given under the code section
3. Paste it as the content of your function
4. Remove the following lines -
if (drupal_strlen($object->name) > 20) {
$name = drupal_substr($object->name, 0, 15) .'...';
}
else {
$name = $object->name;
}
and in place of them just write -
$name = $object->name;
5. Clear the Drupal cache
That should do the trick
_
I did this, and instead of removing/replacing the following lines...
...I edited them and did...
It didn't work. Shouldn't it?
I will try removing the lines and replacing them with the line you suggested, but I assumed that it would work by doing it my way and just making the values larger. No?
_
Tried as you said, still doesn't want to work for me.
Here's the code I'm using.
I also tried it as you suggested and used this code...
No luck.
Sorry for a very late reply,
Sorry for a very late reply, I did not get any notification about your reply. Hopefully you already found a solution. "function theme_username($object)" - the word "theme" in the function name should be replaced by the name of your theme.
_
Sorry, I was using the correct function name, I simply hadn't changed it in my comments. I am using "function theme_username($object)" and replacing "theme" with the name of my theme. Here's the code and I just tried it again to be certain. I'm getting a blank white page after I upload and refresh.
I am experiencing this issue in Drupal 7
Hi, I am experiencing this issue in Drupal 7 and cannot get the code above to work. Can anyone please help? Thanks!
usernames trimmed (with ellipses) in blocks and views
Hi,
In Drupal 7 in order to avoid the username trimming, you should override the template_preprocess_username /http://api.drupal.org/api/drupal/includes--theme.inc/function/template_p...) changing or deleting where says:
(if (drupal_strlen($name) > 20) {
$name = drupal_substr($name, 0, 15) . '...';
}
In Drupal 7, this works for
In Drupal 7, this works for me:
change the numbers as desired and be sure to change
MYTHEMEto the name of your theme. Put this code in your theme's template.php file.Danny Englander | Twitter | Instagram
Thanks highrockmedia! That
Thanks highrockmedia! That works!
If you want to simply show
If you want to simply show the full username, this can be simplified to:
Thank you Sam152. You saved
Thank you Sam152. You saved me some time here.
Thank you, Sam152
This worked great!
perfect solution Sam152
perfect solution Sam152
Thanks, works great for me!
Thanks,
works great for me!
Great tip thanks Sam152
Great tip thanks Sam152 appreciated!
This also works in D8
For those working in D8, this works in D8 as well. I added the snippet to the YOURTHEME_NAME.theme file for your theme.
Thanks @Sam152!
Thank You
Yes, this worked for me too - thank you very, very much. But per my comment below, the fact that we even need this entire thread is absurd. Thanks for at least helping to stem the tide of the absurdity.
maybe add a check_plain
maybe add a check_plain for security
$vars['name'] = check_plain($vars['name_raw']);KOBA - Drupal Webdesign & Webdevelopment
Awesome. Works great.
Awesome. Works great. Thanks. :)
I love Drupal, but...
I love Drupal, but the fact that we need this whole thread is absurd. Why truncate the data? Why not forward all the data to the theme by default, and let the theme decide how much of it to show in the view? {shakes head}
Came here for the same reason
Came here for the same reason: 'why is Views trimming my usernames??' Let the builder decide, not the system.
======
There are 10 people who can count binary
They who can and they who don't
Simpler views based solution
If you don't want to mess around in the code and are just dealing with an issue with user names that are links in views, here's a simpler solution from Morten Najbjerg:
From: https://www.drupal.org/node/1445404#comment-5808950
Drupal 8 Easy Solution
- Disable "Link to user" in the settings of the Username field
- Use instead a rewrite rule: "Output this field as a custom link" and set it to: /user/
That's it
For Drupal 8 Solution
In view's user filed, I selected 'plain text' in formatter instead of User name, and it worked. You can select 'plain text' in formatter and Link to the user and it will work.