function UserHooksTest::userFormatNameAlter
Alters the username.
Attributes
#[Hook('user_format_name_alter')]
Parameters
string|\Drupal\Component\Render\MarkupInterface $name: The username that is displayed for a user.
\Drupal\Core\Session\AccountInterface $account: The object on which the operation is being performed.
File
-
core/
modules/ user/ tests/ modules/ user_hooks_test/ src/ Hook/ UserHooksTest.php, line 24
Class
- UserHooksTest
- Contains hook implementations.
Namespace
Drupal\user_hooks_test\HookCode
public function userFormatNameAlter(&$name, AccountInterface $account) : void {
if (\Drupal::keyValue('user_hooks_test')->get('user_format_name_alter', FALSE)) {
if (\Drupal::keyValue('user_hooks_test')->get('user_format_name_alter_safe', FALSE)) {
$name = new FormattableMarkup('<em>@uid</em>', [
'@uid' => $account->id(),
]);
}
else {
$name = '<em>' . $account->id() . '</em>';
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.