function realname_user_view in Real Name 8
Same name and namespace in other branches
- 6 realname.module \realname_user_view()
- 7 realname.module \realname_user_view()
- 2.x realname.module \realname_user_view()
Implements hook_ENTITY_TYPE_view() for user entities.
File
- ./
realname.module, line 117 - Provides token-based name displays for users.
Code
function realname_user_view(array &$build, EntityInterface $account, EntityViewDisplayInterface $display, $view_mode) {
if ($display
->getComponent('realname')) {
if ($account
->access('view')) {
$url = Url::fromRoute('entity.user.canonical', [
'user' => $account
->id(),
]);
$markup = Link::fromTextAndUrl($account->realname, $url)
->toString();
}
else {
$markup = Html::escape($account->realname);
}
$build['realname'] = [
'#theme' => 'field',
'#title' => t('Real name'),
'#label_display' => 'inline',
'#view_mode' => '_custom',
'#field_name' => 'realname',
'#field_type' => 'text',
'#field_translatable' => FALSE,
'#entity_type' => 'custom',
'#bundle' => 'custom',
'#object' => $account,
'#items' => [
TRUE,
],
'#is_multiple' => FALSE,
0 => [
'#markup' => $markup,
],
];
}
}