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.
string $name: The string that $account->getDisplayName() will return.
$account: The account object the name belongs to.
\Drupal\Core\Session\AccountInterface->getDisplayName()
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())); } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!user!user.api.php/function/hook_user_format_name_alter/8.1.x