Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By webchick on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
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
Comments
What about 'user_profile_category' ?
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 :