user_user_view_alter(array &$build, UserInterface $account, EntityViewDisplayInterface $display)
Implements hook_ENTITY_TYPE_view_alter() for user entities.
This function adds a default alt tag to the user_picture field to maintain accessibility.
File
- core/modules/user/user.module, line 387
- Enables the user registration and login system.
Code
function user_user_view_alter(array &$build, UserInterface $account, EntityViewDisplayInterface $display) {
if (user_picture_enabled() && !empty($build['user_picture'])) {
foreach (Element::children($build['user_picture']) as $key) {
$item = $build['user_picture'][$key]['#item'];
if (!$item->get('alt')->getValue()) {
$item->get('alt')->setValue(\Drupal::translation()->translate('Profile picture for user @username', ['@username' => $account->getUsername()]));
}
}
}
}
Please login to continue.