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

  • gapple committed 7057fd0 on 7.x-1.x
    Issue #1975976 by gapple, DuaelFr: Implement hook_field_extra_fields()...
gapple’s picture

Title: Do not just implement hook_user_view » Implement hook_field_extra_fields() for information on user page
Issue summary: View changes
Status: Active » Fixed

Thank you for the suggestion and code snippet.

Committed to 7.x-1.x-dev

DuaelFr’s picture

No, 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).

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.