function theme_username

Returns HTML for a username, potentially linked to the user's page.

Parameters

$variables: An associative array containing:

  • account: The user object to format.
  • name: The user's name, sanitized.
  • extra: Additional text to append to the user's name, sanitized.
  • link_path: The path or URL of the user's profile page, home page, or other desired page to link to for more information about the user.
  • link_options: An array of options to pass to the l() function's $options parameter if linking the user's name to the user's page.
  • attributes: An array of attributes to instantiate the Drupal\Core\Template\Attribute class if not linking to the user's page.

See also

template_preprocess_username()

template_process_username()

26 theme calls to theme_username()
CommentFormController::form in drupal/core/modules/comment/lib/Drupal/comment/CommentFormController.php
Overrides Drupal\Core\Entity\EntityFormController::form().
comment_admin_overview in drupal/core/modules/comment/comment.admin.inc
Form constructor for the comment overview administration form.
contact_personal_form in drupal/core/modules/contact/contact.pages.inc
Page callback: Form constructor for the personal contact form.
dblog_event in drupal/core/modules/dblog/dblog.admin.inc
Page callback: Displays details about a specific database log message.
dblog_overview in drupal/core/modules/dblog/dblog.admin.inc
Page callback: Displays a listing of database log messages.

... See full list

File

drupal/core/modules/user/user.module, line 966
Enables the user registration and login system.

Code

function theme_username($variables) {
  if (isset($variables['link_path'])) {

    // We have a link path, so we should generate a link using l().
    // Additional classes may be added as array elements like
    // $variables['link_options']['attributes']['class'][] = 'myclass';
    $output = l($variables['name'] . $variables['extra'], $variables['link_path'], $variables['link_options']);
  }
  else {

    // Modules may have added important attributes so they must be included
    // in the output. Additional classes may be added as array elements like
    // $variables['attributes']['class'][] = 'myclass';
    $output = '<span' . new Attribute($variables['attributes']) . '>' . $variables['name'] . $variables['extra'] . '</span>';
  }
  return $output;
}