function name_user_format_name_alter in Name Field 8
Implements hook_user_format_name_alter().
File
- ./
name.module, line 108 - Defines an API for displaying and inputing names.
Code
function name_user_format_name_alter(&$name, AccountInterface $account) {
// Don't alter anonymous users or objects that do not have any user ID.
if ($account
->isAnonymous()) {
return;
}
// Try and load the realname in case this is a partial user object or
// another object, such as a node or comment.
if (!isset($account->realname)) {
name_user_format_name_alter_preload($account);
}
// Since $account may not be the real User entity object, check the name
// lookup cache for results too.
if (!isset($account->realname) || !mb_strlen($account->realname)) {
$names =& drupal_static('name_user_realname_cache', []);
if (isset($names[$account
->id()])) {
$account->realname = $names[$account
->id()];
}
}
if (isset($account->realname) && mb_strlen($account->realname)) {
$name = $account->realname;
}
}