Problem/Motivation

Very often people need a way to disable display and username truncating, but core theme_username always truncates at 20 chars. Screens become wider and wider and this limit should be removed or at least increasable. There are also situation where module maintainers like to disable the truncating or know how wide their tables are and they have more space. In such a case they should be able to increase the length.

Proposed resolution

Custom settings to conditionally disable or change the behaviour.

  • 'format_username' => TRUE,
  • 'truncate' => TRUE,
  • 'max_length' => 20,

Remaining tasks

Review the patch.

User interface changes

None.

API changes

None, just 3 new variables.

Data model changes

None.

Comments

hass created an issue. See original summary.

hass’s picture

Issue summary: View changes
hass’s picture

Status: Active » Needs review
strykaizer’s picture

Status: Needs review » Needs work

Drupal core truncates to 15 characters when username has more then 20 characters.
Lets keep the output for default settings when truncated the same as core does now to prevent possible tests (in contrib) from failing.

hass’s picture

Status: Needs work » Needs review

How should this happen? The code truncates only if longer than 20 chars like before. There is no change. If format_username() is propery used, nothing can go wrong. I only removed an outdated workaround (hardcoded 5 chars) that should not used as there is the truncate utf8 function that works properly compared to substr.

strykaizer’s picture

Status: Needs review » Needs work

@hass

While I do agree that your patch makes more sense than current core solution, it does involves a change though.

If i'm not mistaken, atm, when a username is 20+ characters long, core keeps only 15 characters (and 3 dots).
This patch brakes possible tests with usernames 20+ characters long since truncate_utf8 will change it to 17 characters (+ 3 dots)

hass’s picture

This can only happen if someone does NOT use the Drupal API format_username(). In such a case - the module has a bug and need to be corrected, too. By this change, we find them...

tatarbj’s picture

Status: Needs work » Needs review
StatusFileSize
new1.39 KB
new376 bytes

Hi all,
after testing the patch it's true it truncates differently the username as before because of the previously hardcoded 15 character goes up to 17. In order to change nothing for backward compatibility i've modified the patch to not at max_length of 20, but 18 (see interdiff).
I think this will guarantee all tests from core (as before), but also from contribs and even site specific tests will remain green.
Otherwise the proposal is really nice, because currently we are not able to truncate username as we would like to!
Bests,
Balazs.

hass’s picture

That is still a change as we only abrivated the username if longer than 20 letters. My patch was safer

dpi’s picture

Version: 7.x-dev » 8.8.x-dev
Category: Bug report » Feature request

Username is truncated in Drupal 8.

This is more of a feature than a bug.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

izmeez’s picture

StatusFileSize
new290 bytes

Not sure what the directions are for this issue but just incase anyone is interested attached is an interdiff for the 7.x patches in #1 and #8.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

sourabhrawat’s picture

Use following code in your theme

function THEME_preprocess_username(&$vars) {
//putting back what drupal core messed with
$vars['username'] = check_plain($vars['name_raw']);
}

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new171 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.