You are here

function user_user_view_alter in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/user.module \user_user_view_alter()

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