function template_preprocess_username template_preprocess_username(&$variables) Prepares variables for username templates. Default template: username.html.twig. Modules that make any changes to variables like 'name' or 'extra' must ensure that the final string is safe. Parameters  array $variables: An associative array containing:  
account: The user account (\Drupal\Core\Session\AccountInterface).  File
 core/modules/user/user.module, line 456 Enables the user registration and login system.  Code function template_preprocess_username(&$variables) {
  $account = $variables['account'] ? : new AnonymousUserSession();

  $variables['extra'] = '';
  $variables['uid'] = $account->id();
  if (empty($variables['uid'])) {
    if (theme_get_setting('features.comment_user_verification')) {
      $variables['extra'] = ' (' . t('not verified') . ')';
    }
  }

  // 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 = $account->getDisplayName();
  $variables['name_raw'] = $account->getUsername();
  if (Unico8b7c:f320:99b9:690f:4595:cd17:293a:c069strlen($name) > 20) {
    $name = Unico8b7c:f320:99b9:690f:4595:cd17:293a:c069truncate($name, 15, FALSE, TRUE);
    $variables['truncated'] = TRUE;
  }
  else {
    $variables['truncated'] = FALSE;
  }
  $variables['name'] = $name;
  $variables['profile_access'] = \Drupal8b7c:f320:99b9:690f:4595:cd17:293a:c069urrentUser()->hasPermission('access user profiles');

  $external = FALSE;
  // Populate link path and attributes if appropriate.
  if ($variables['uid'] && $variables['profile_access']) {
    // We are linking to a local user.
    $variables['attributes']['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['attributes']['rel'] = 'nofollow';
    $variables['link_path'] = $account->homepage;
    $variables['homepage'] = $account->homepage;
    $external = TRUE;
  }
  // We have a link path, so we should generate a URL.
  if (isset($variables['link_path'])) {
    if ($external) {
      $variables['attributes']['href'] = Url8b7c:f320:99b9:690f:4595:cd17:293a:c069romUri($variables['link_path'], $variables['link_options'])
        ->toString();
    }
    else {
      $variables['attributes']['href'] = Url8b7c:f320:99b9:690f:4595:cd17:293a:c069romRoute('entity.user.canonical', array(
        'user' => $variables['uid'],
      ))->toString();
    }
  }
}


    
{'path': 'public/docs/drupal~8/core-modules-user-user.module/function/template_preprocess_username/8.1.x.html', 'source': 'DevDocs.IO'}