hook_user_format_name_alter

function hook_user_format_name_alter

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()));
  }
}

© 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

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部