When Profile2 fields are used as tokens for the Realname, the Realname is blank after initial user registration. Re-saving the user account, or the Profile2 profile populates the Realname as expected.

Steps to reproduce:

1) Install a fresh Drupal 7 install.
2) Download and enable the following modules: entity, token, profile2, realname (also enable the entity_token module)
3) Add a "First name" and "Last name" field to the default "Main profile" type.
4) Confirm that the "Show during user account registration." is checked on the profile edit page.
5) Configure the Realname module to use these tokens: "[user:profile-main:field-first-name] [user:profile-main:field-last-name]"
6) Register a new account with the site and confirm that the Realname table row created contains an empty string for the realname column. Edit and re-save the user account form and confirm that the Realname is now properly generated.

7) Edit the profile and change the name(s). Realname is not updated until you edit and save the user form.

Original report:

I am unable to determine the cause of this bug. I am using profile2 and I created a field called field_full_name that shows up on the registration page. After registration, the realname column for the registered user is an empty string.

If I edit the profile and save it without making any changes, then the realname is correctly computed.

Do you know what the cause of this problem might be?

Thanks!

Comments

zarudnyi’s picture

Same here. Real Name appear only after re-saving.
Thanks!

dave reid’s picture

Project: Real Name » Profile 2
Version: 7.x-1.0-beta1 » 7.x-1.x-dev

I added just a simple text field to the user entity and had it show up on registration and the realname was generated correctly. So something with profile2 or entity_token's tokens is at fault here for not providing the correct information in its tokens.

fago’s picture

Status: Active » Postponed (maintainer needs more info)

How is that supposed to work? We have realname in the user account that gets filled via a token pointing to a field in profile2? If so, how is that triggered?

zarudnyi’s picture

Thank You for answer.
You want to say that the user will be presented on the site under his login, until not resave his profile?
This logic has worked in the sixth branch of the module.

jessehs’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs work

Updating issue summary with steps to reproduce.

jessehs’s picture

I think the following issue might be related: #2022137: Always update realname on user updates

The last comment suggests that profile2 should run the realname update if a profile has changed (or in this case has been created).

jessehs’s picture

Updating title with new (I think related) symptom.

iamcarrico’s picture

Project: Profile 2 » Real Name
Status: Needs work » Needs review

All that (should) need to happen is the Real Name module implementing some of the hooks in Profile2. Skipping a full patch, because I am lazy today--- but there is the code:

/**
 * Implements hook_profile2_update().
 */
function realname_profile2_update($profile) {
  $account = user_load($profile->uid);
  realname_update($account);
}

/**
 * Implements hook_profile2_insert().
 */
function realname_profile2_insert($profile) {
  $account = user_load($profile->uid);
  realname_update($account);
}
gaurishankar’s picture

@iamcarrico, Can more elaborate about your patch? In which file i have to put up this code.

iamcarrico’s picture

Just in the primary .module file. The two hooks will update the realname settings if the profile2 settings are updated, similar to how it is already being done for the user accounts.

hass’s picture

Status: Needs review » Closed (duplicate)
jessehs’s picture

Issue summary: View changes
Status: Closed (duplicate) » Needs work

I tested the fix in #8 and can confirm that implementing these hooks does not fix the issue. I followed the steps to reproduce the issue in the description and the problem is still occurring.

I believe that perhaps there may be a static cache having to do with token generation that needs to be reset (or something of the like, I don't know). The tokens provided by Profile2 fields are empty during user registration, so the Realname is not set until the user account is re-saved.

jessehs’s picture

Status: Needs work » Closed (duplicate)

Oh, I see the duplicated issue. Sorry :)

joeyroth’s picture

it's works when the user update the field, but when is insert for the first time it don't work,

youfei.sun’s picture

Status: Closed (duplicate) » Active

Agreed, it is not working when inserting the profile. And the duplicate issue is actually talking about a different issue.

hass’s picture

Issue tags: +Need tests
youfei.sun’s picture

Forgot to add workaround for this issue:

The realname_update($account) only works after the data is already inserted.
So you have to include this module for hook_entity_postinsert($entity, $entity_type)

and add this

function hook_entity_postupdate($entity,$entity_type) {
  if($entity_type == 'profile2'){
    $account = user_load($entity->uid);
    realname_update($account);
  }
}

function hook_entity_postinsert($entity,$entity_type) {
  if($entity_type == 'profile2'){
    $account = user_load($entity->uid);
    realname_update($account);
  }
}

(don't forget replace hook to the module name, you can add this code in realname, but I added into my custom module in case realname updates)

archimedes’s picture

We have a similar issue where the "view" tab of the user profile is showing Username instead (as is the one-time login landing page). Also running Profile2 with a Profile2 field in the Real Name slot.

geek-merlin’s picture

Status: Active » Needs review
StatusFileSize
new1012 bytes

Trivial patch flying in as @donquixote outlined and @hass confirmed in #2303599-7: Implement hook_profile2_update().

Have fun!

hass’s picture

How about a test to prove the functionality? I'm wondering why the profile::save is not fixed and we are only adding bandaids!?!?

geek-merlin’s picture

> I'm wondering why the profile::save is not fixed and we are only adding bandaids?

I looked into that and it would need quite some refactoring, sigh... (and a new maintainer...)

hass’s picture

I 100% agree to not implementing bandadis... last patch made this very clear to me. Should not fixed here.

Should we close as duplicate?

geek-merlin’s picture

Let's separater this:
You may call the line "drupal_static_reset..." a bandaid for profile2.
but the rest is just implementing the forgotten hook_insert while the hook_update is already implemented.

pelicani’s picture

We are having this same problem, but are not using Profile2.
We are using the Core Drupal User Fields, but have the exact same problem.
We put custom user field tokens in the RealName.

If there isn't a bandaid fix, I hope that it will fix this similar problem that I've encountered.

peace,
michael

pelicani’s picture

We solved this by adding a hook user insert to the real name module.
Works for us.
Would this also work for profile2?

We are running our code though QA and if it passes we should make a patch and share.

peace,
michael

hass’s picture

Status: Needs review » Closed (duplicate)

Profile2 need to be fixed.