Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

In Drupal 8, when adding additional elements to the user profile via hook_user_view(), the #type 'user_profile_item' no longer exists, in favour of #type 'item' instead.

If your module still specifies '#type' => 'user_profile_item' in Drupal 8, you will end up only seeing the value of the field on the user profile, not also its label.

Drupal 7

function hook_user_view($account, $view_mode, $langcode) {
  $account->content['summary']['member_for'] = array(
     '#type' => 'user_profile_item',
     '#title' => t('Member for'),
     '#markup' => format_interval(REQUEST_TIME - $account->created),
  );
}

Drupal 8

function hook_user_view(array &$build, \Drupal\user\UserInterface $account, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) {
  if ($display->getComponent('member_for')) {
    $build['member_for'] = array(
      '#type' => 'item',
      '#title' => t('Member for'),
      '#markup' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $account->getCreatedTime()),
    );
  }
}
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

ccrosaz’s picture

Drupal 8 User module get rid of the 'user_profile_category' called 'summary'. Now we can use other possibilities ('details', 'container', ...), but the render can be different from other modules.

Their is also a minor change in the user module, the title is now part of the #markup :

/**
 * Implements hook_ENTITY_TYPE_view() for user entities.
 */
function user_user_view(array &$build, UserInterface $account, EntityViewDisplayInterface $display) {
  if ($display->getComponent('member_for')) {
    $build['member_for'] = [
      '#type' => 'item',
      '#markup' => '<h4 class="label">' . t('Member for') . '</h4> ' . \Drupal::service('date.formatter')->formatTimeDiffSince($account->getCreatedTime()),
    ];
  }
}