In Drupal 8, long comment author names are truncated. These comments are from anonymous users. When I use the following preprocess function, Drupal responds with a HTTP 500 code, and I have to restore the site from backup.

function THEME_preprocess_username(&$vars) {
    $vars['name'] = check_plain($vars['name_raw']);

Is there another way of removing the truncation from author names in comments?

1 Answer 1


You are likely getting an error because the check_plain() function doesn't exist in Drupal 8. Your error logs should be able to confirm that.

If you check the main template_preprocess_username() function where the truncated version of the name is set, you can see it uses User::getDisplayName() and then truncates that.

So you could do this:

function THEME_preprocess_username(&$variables) {
  $account = $variables['account'] ?: new AnonymousUserSession();
  $variables['name'] = $account->getDisplayName();

If you want to keep with the check_plain() approach from your example, in Drupal 8 you can use Html::escape().


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.