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!
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | realname-1044130-19-hook-profile2-insert.patch | 1012 bytes | geek-merlin |
Comments
Comment #1
zarudnyi commentedSame here. Real Name appear only after re-saving.
Thanks!
Comment #2
dave reidI 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.
Comment #3
fagoHow 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?
Comment #4
zarudnyi commentedThank 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.
Comment #5
jessehsUpdating issue summary with steps to reproduce.
Comment #6
jessehsI 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).
Comment #7
jessehsUpdating title with new (I think related) symptom.
Comment #8
iamcarrico commentedAll 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:
Comment #9
gaurishankar@iamcarrico, Can more elaborate about your patch? In which file i have to put up this code.
Comment #10
iamcarrico commentedJust 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.
Comment #11
hass commentedComment #12
jessehsI 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.
Comment #13
jessehsOh, I see the duplicated issue. Sorry :)
Comment #14
joeyroth commentedit's works when the user update the field, but when is insert for the first time it don't work,
Comment #15
youfei.sun commentedAgreed, it is not working when inserting the profile. And the duplicate issue is actually talking about a different issue.
Comment #16
hass commentedComment #17
youfei.sun commentedForgot 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
(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)
Comment #18
archimedes commentedWe 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.
Comment #19
geek-merlinTrivial patch flying in as @donquixote outlined and @hass confirmed in #2303599-7: Implement hook_profile2_update().
Have fun!
Comment #20
hass commentedHow about a test to prove the functionality? I'm wondering why the profile::save is not fixed and we are only adding bandaids!?!?
Comment #21
geek-merlin> 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...)
Comment #22
hass commentedI 100% agree to not implementing bandadis... last patch made this very clear to me. Should not fixed here.
Should we close as duplicate?
Comment #23
geek-merlinLet'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.
Comment #24
pelicani commentedWe 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
Comment #25
pelicani commentedWe 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
Comment #26
hass commentedProfile2 need to be fixed.