hook_user_format_name_alter(&$name, $account)
Alter the username that is displayed for a user.
Called by $account->getDisplayName() to allow modules to alter the username that is displayed. Can be used to ensure user privacy in situations where $account->getDisplayName() is too revealing.
Parameters
string $name: The string that $account->getDisplayName() will return.
$account: The account object the name belongs to.
See also
\Drupal\Core\Session\AccountInterface::getDisplayName()
Related topics
- Hooks
 - Define functions that alter the behavior of Drupal core.
 
File
- core/modules/user/user.api.php, line 120
 - Hooks provided by the User module.
 
Code
function hook_user_format_name_alter(&$name, $account) {
  // Display the user's uid instead of name.
  if ($account->id()) {
    $name = t('User @uid', array('@uid' => $account->id()));
  }
}
Please login to continue.