Some people might not like it when long usernames are cropped in the node haeder. This patch can be applied to includes/common.inc version 4.5.2 and creates a new variable 'user_name_crop' to adjust the crop length.

CommentFileSizeAuthor
#2 common_1.diff544 bytesñull
common_0.diff546 bytesñull
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Uwe Hermann’s picture

ñull’s picture

FileSize
544 bytes

I had the numbers wrong. In the original code it was cropped at 15, not at 10 like in my diff. I also changed it a bit to avoid negative argaments. Attached the new diff from version 4.5.2.

   if ($object->uid && $object->name) {
     // Shorten the name when it is too long or it will break many tables.
    if (strlen($object->name) > variable_get('user_name_crop', 15)+5) {
      $name = truncate_utf8($object->name, variable_get('user_name_crop', 15)) .'...';
     }
     else {
       $name = $object->name;
Bèr Kessels’s picture

IMO this should be done in a theme, not with yet another config option.
what about theme_username() ?

killes@www.drop.org’s picture

theme_username++
format_name is one of the functions I always need to modify. theme_date would be nice, too.

Dries’s picture

This should be done in the theme.

tangent’s picture

In some cases there may not be a need to truncate the output at all. We should consider using CSS to adjust the display of text rather than truncating strings to arbitrary lengths that may be less than can be viewed in a given resolution.

Given the following markup

<div class="container">
  This is a string which may be displayed in a
  small area and may be truncated if the container
  is too small to contain it.
</div>

the following CSS may be used to control the overflow of the container.

.container {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Use of the proprietary (MS Internet Explorer) "text-overflow" property may be used to show ellipsis on a container with hidden content. Javascript could be used to display ellipsis on these containers for other browsers as well, though it may well not be worth doing so.

Using CSS to control display in this manner gives greater control for supporting variable environments (graphical browser, wap browser, text browser) without limiting the content that I user needs to see.

ñull’s picture

According to that reasoning, the username crop should be taken out of the code, because the problem can be solved through CSS. Whatever the way to solve this problem, it should be configurable by the user. At the moment the code decides it for me and I cannot show the letters with CSS were code cropped it away for me.

killes@www.drop.org’s picture

This issue should be fixed by makinf format_name themable. Marking active.

ñull’s picture

ñull’s picture

Assigned: ñull » Unassigned
adrian’s picture

Status: Active » Closed (fixed)

we now have theme_username