Hi,

I was having issues with Field_group and profile2. When having multiple profile type in the registration page with fieldsets the first content type's fieldset were not showing at all.

After investigating the code I have figured that a pre_render was executed twice so this was not properly rendering the fieldsets.

Here's what I have figured:

profile2.module

AFTER LINE: 411 ADD:
$form['profile_' . $profile->type]['#pre_render'] = array_unique($form['profile_' . $profile->type]['#pre_render']);

RESULTs:
function profile2_attach_form(&$form, &$form_state) {
  foreach ($form_state['profiles'] as $type => $profile) {
    $form['profile_' . $profile->type]['#tree'] = TRUE;
    $form['profile_' . $profile->type]['#parents'] = array('profile_' . $profile->type);
    field_attach_form('profile2', $profile, $form['profile_' . $profile->type], $form_state);

    if (count(field_info_instances('profile2', $profile->type)) == 0) {
      $form['profile_' . $profile->type]['message'] = array(
        '#access' => user_access('administer profile types'),
        '#markup' => t('No fields have been associated with this profile type. Go to the <a href="!url">Profile types</a> page to add some fields.', array('!url' => url('admin/structure/profiles'))),
      );
    }

    // Provide a central place for modules to alter the profile forms, but
    // skip that in case the caller cares about invoking the hooks.
    // @see profile2_form().
    if (!isset($form_state['profile2_skip_hook'])) {
      $hooks[] = 'form_profile2_edit_' . $type . '_form';
      $hooks[] = 'form_profile2_form';
      drupal_alter($hooks, $form, $form_state);
    }
    $form['profile_' . $profile->type]['#pre_render'] = array_unique($form['profile_' . $profile->type]['#pre_render']);		
  }
	
  $form['#validate'][] = 'profile2_form_validate_handler';
  $form['#submit'][] = 'profile2_form_submit_handler';
}

CommentFileSizeAuthor
#29 profile2-dedupe_pre_render-1209640-29.patch576 bytesrickj
#18 profile2-dedupe_pre_render-1209640-18.patch577 bytesrooby
#16 user_account.png15.39 KBAnonymous (not verified)
#16 main_profile.png18.75 KBAnonymous (not verified)
#11 pic-2.jpg91.54 KBspleshka
#11 pic-1.jpg90.29 KBspleshka

Comments

Stalski’s picture

Title: Bug with Field_group » The main profile is loaded twice resulting in pre_render getting execute twice (extra fields, field_groups, ...)

I tested this and indeed, that's the reason. The reason is that the main profile is executed twice as it is in form state.
See $form_state['profiles'] contains [main, main, mycustomprofile]

The reason is that internally, the main always exists and is loaded again in the registered profiles.

Also changing title so it explains the problem in detail.

webadpro’s picture

Great. Atlease we've got it figured out.

fago’s picture

Version: 7.x-1.0-beta4 » 7.x-1.x-dev
Status: Active » Postponed (maintainer needs more info)

Is this still an issue?

leramulina’s picture

Tell me, please, what's the solution of this problem?

webadpro’s picture

Read the first post. Everything is there to fix the issue.

Anonymous’s picture

Has there been any follow up on this issue? It is still a problem (Jan 2014).

The above core hack might work, but where is it added? I assume "After Line 411" is no longer accurate?

burgs’s picture

Well, I can confirm that the suggested solution does fix the problem. Are we happy to roll a patch for this and get it submitted?

spleshka’s picture

Status: Postponed (maintainer needs more info) » Needs review

I don't mind commiting this. I will take some time soon and commit this, in case if solution really works.

burgs’s picture

Thanks Spleshka, much appreciated :)

entropYBRO’s picture

i can validate that the above given patch is working

spleshka’s picture

Status: Needs review » Postponed (maintainer needs more info)
StatusFileSize
new90.29 KB
new91.54 KB

I cannot reproduce this bug. See user settings:

And this is registration form:

Everything works properly. If it doesn't work for you, please provide a detailed steps to reproduce.

burgs’s picture

Spleshka, are you saying that you don't get the problem, without the patch?
I was getting the problem on the user edit screen, with multiple profile2s being edited on the same page. The groups in one of the Profile2s weren't showing until I made them vertical tabs.

spleshka’s picture

@burgs, yes, I didn't apply any patches. I just configured field group and two profile types, and it just works.
P.S. I am using latest dev version.

alfthecat’s picture

Is this related to #2124561: Profile2 page no longer displays.?

I can create user profile types, add fields to them but when I try to edit one, the fields that I added to the profile types don't show and the regular user account settings appear.

Profile2 doesn't seem to work at all. I do have the fieldgroup module installed but none of my profile type fields are grouped, nor are the fields in the account settings (I'm introducing profile2 to a site that already had fields added to the user accounts).

This is both with the 1.3 and the latest dev version.

Anonymous’s picture

Having the same problem, I applied the described change. In the actual dev version:

adding

$form['profile_' . $profile->type]['#pre_render'] = array_unique($form['profile_' . $profile->type]['#pre_render']);

at line 453 of profile2.module. (End of foreach loop of the function profile2_attach_form)

After that the fields of the first profile (and the second) where displayed again on the registration form.

Anonymous’s picture

StatusFileSize
new18.75 KB
new15.39 KB

I have reproduced this error in a fresh Drupal install with the following steps:

1. Minimal install of Drupal (I used D7, actual production version)
2. Install profile2 with required modules (I used the actual dev version)
3. install field group with required module
4. add to main profile (see picture):
- texfield test3
- field group (I used 7.x-1.4, the actual production version)
- underlying field test1
5. Create a new profile with a textfield test2
6. Set both profiles to ‘Show during useraccount registration’
7. Log out
8. Try registering under this new site. Text field test1 will not show (see picture). After patching the field will show.

I hope the patch can be added to the module. This kind of problems cost a lot of time to solve and make Drupal difficult to digest as we say in the Netherlands.

dready2011’s picture

I can confirm that this solved my issues with displaying fieldgroups from multiple profile2 profiles on the user/edit form as well! Thanks so much, spend a lot of time on this. Will link to this issue from related issues.

rooby’s picture

Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new577 bytes

Here is a patch of the fix mentioned in the initial post.

It fixed my problem of missing field groups on a user add page with multiple profile2 profiles.

Without actually doing any further investigation of my own, on the surface this seems like a bandaid fix that isn't fixing the underlying problem of why we're getting the duplicate pre_render's in the first place.
If we have duplicate pre-renders then maybe we have other duplicate things causing other problems.

The patch is for latest dev but still applies with offset to 7.x-1.3.

rooby’s picture

  • Spleshka committed 2de68f2 on 7.x-1.x
    Issue #1209640 by rooby, Spleshka, Jaapx, burgs: The main profile is...
spleshka’s picture

Status: Needs review » Fixed

Hi everybody, sorry for the late response. Thanks a lot @Jaapx for the steps to reproduce the issue and @rooby for the patch - it really helped me to find out the root of the bug and fix it. And thanks everybody for your help!

The issue is fixed now and commited to 7.x-1.x. The fix also includes small performance bump, because we avoid duplicated calls of field_attach_form() introduced by each next profile type.

Status: Fixed » Closed (fixed)

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

shi99’s picture

Hello,

For me this issue is not fixed on dev. For user registration the fieldsets are not being shown.
The patch from #18 solved the issue for me.

Thanks

vinmassaro’s picture

Can't reopen this issue but updating to 7.x-1.x-dev removed profile feeds for me. Patching with #18 fixed the issue.

ikeigenwijs’s picture

I can confirm patch in # 18 works for drupal 7.54 profile2 version dev-20 latest at this moment

donapis’s picture

Patch in # 18 works for drupal 7.56 profile2 version dev-20. Thanks

shahidaali’s picture

Patch in # 18 worked for me too.

alex.bukach’s picture

@Spleshka the commit looks completely different from the patch #18, the issue still exists, and the patch #18 still fixes it.

rickj’s picture

Assigned: Unassigned » rickj
Status: Closed (fixed) » Needs review
StatusFileSize
new576 bytes

I agree, it doesn't look like the fix in #18 has been applied. I don't know if what was actually changed was supposed to have the same effect, but that doesn't seem to have been the result.

I've re-rolled #18 to apply to latest dev, can people check this out with dev+3 and let us know?

jeff.hartman’s picture

Edit: I can confirm that the patch in #29 when applied to 7.x-1.4+3-dev works for me.

(Sorry: a previous edit to this comment said it didn't work. I thought the patch was already rolled into the dev branch vs. needing to be applied to the dev branch.)

rickj’s picture

Thanks for the feedback Jeff. Sorry if my comment was confusing, but this patch won't be committed to dev until there's more feedback to confirm that it's the correct solution.

rickj’s picture

Status: Needs review » Reviewed & tested by the community

@jdleonard: thanks for the feedback and cross-referencing. The patch looks good, marking RTBC. Will commit soon.

  • RickJ committed bdf0edd on 7.x-1.x
    Issue #1209640 by RickJ, rooby: The main profile is loaded twice...
jdleonard’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

rickj’s picture

Assigned: rickj » Unassigned