1 user.theme.inc | theme_username($variables) |
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 pass to the backdrop_attributes() function if not linking to the user's page.
$variables['account'] is typically a User object, but it can be any object that provides the uid and name properties, for example, a Node.
See also
template_preprocess_username()
File
- core/
modules/ user/ user.theme.inc, line 75 - Theme functions for the User module.
Code
function theme_username($variables) {
if (isset($variables['link_path'])) {
// Finalize the link_options array for passing to the l() function.
// Additional classes may be added here as array elements like
// $variables['attributes']['class'][] = 'myclass';
// $variables['attributes'] contains attributes that should be applied
// regardless of whether a link is being rendered.
// $variables['link_attributes'] contains attributes that should only be
// applied if a link is being rendered.
// If a link is being rendered, these need to be merged. Some attributes are
// themselves arrays, so the merging needs to be recursive.
$variables['link_options']['attributes'] = array_merge_recursive($variables['link_attributes'], $variables['attributes']);
// We have a link path, so we should generate a link using l().
$output = l($variables['name'] . $variables['extra'], $variables['link_path'], $variables['link_options']);
}
else {
$output = '<span' . backdrop_attributes($variables['attributes']) . '>' . $variables['name'] . $variables['extra'] . '</span>';
}
return $output;
}