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 using hook_user_view to inject content into an user page without declaring an extra field you are totally ruining efforts of site builders who want to use fields and view modes to show their users on their websites.
Here is a snippet to help :
function persistent_login_field_extra_fields() {
$extra = array();
$extra['user']['user']['display'] = array(
'persistent_login_warning' => array(
'label' => t('Persistent Login warning'),
),
);
return $extra;
}
function persistent_login_user_view($account, $view_mode) {
global $user;
if ($user->uid == $account->uid || user_access('administer persistent login')) {
$settings = field_extra_fields_get_display('user', 'user', $view_mode);
if (!empty($settings['persistent_login_warning']['visible'])) {
// Do you stuff here
}
}
}
I hope you will find this useful even if I didn't have the time to make a proper patch.
Comments
Comment #2
gappleThank you for the suggestion and code snippet.
Committed to 7.x-1.x-dev
Comment #3
DuaelFrNo, thank YOU implementing this and sorry that I did not take the time to provide a patch (I totally forgot this issue to be honest).