1

I have a profile2 Profile that's named Driver. This profile has a Term reference to a vocabulary named Cities that contains over 30.000 terms.

I made a custom user-register.tpl.php by declaring it in my template.php, and in here I display only the form keys that interests me for the account creation.
When I go to driver/register which is the custom page for registering to my profile type, the loading is taking too much time, and I suspect it to be caused by the loading of all the fields of my profile (even those non-rendered) and more especially that vast vocabulary.

I looked into profile2 folders and files trying to comment parts related to the registration but nothing would prevent the loading from happening.
I also tried to unset($form[profile_driver]) in my theme_form_user_register_alter, but it doesn't affect the fact that the profile fields are still loaded before being removed from $form, so I figured it has to be directly in profile2.

Been struggling for quite some days now so if anyone has clues on how to prevent the loading of the whole profile form or ideally specific fields I would be glad to read how to do the trick !
Thanks

7.x-1.4


FINAL EDIT :

I didn't manage to do it programmatically so I ended up setting up a Rule that assigns the Profile & the role to the newly saved user.

0

Been struggling for quite some days now so if anyone has clues on how to prevent the loading of the whole profile form

Looks to me that the magic happens in profile2.module from line 436 to 460

/**
 * Implements hook_form_FORM_ID_alter() for the registration form.
 */
function profile2_form_user_register_form_alter(&$form, &$form_state) {
  foreach (profile2_get_types() as $type_name => $profile_type) {
    if (!empty($profile_type->data['registration'])) {
      if (empty($form_state['profiles'][$type_name])) {
        $form_state['profiles'][$type_name] = profile2_create(array('type' => $type_name));
      }
    }
  }

  // If we have profiles to attach to the registration form - then do it.
  if (!empty($form_state['profiles'])) {
    profile2_attach_form($form, $form_state);

    // Wrap each profile form in a fieldset.
    foreach ($form_state['profiles'] as $type_name => $profile_type) {
      $form['profile_' . $type_name] += array(
        '#type' => 'fieldset',
        '#title' => check_plain($profile_type->getTranslation('label')),
      );
    }
  }
}

Usually I would never hack a contrib module directly, but unfortunately here there is no other option considering you have a profile field that loads 30,000 terms. So comment this out and flush/clear cache.

Just remember if there is ever an update to this module, it will override your changes, so you will have to comment it out again then.

0

Hello and thank you for your answer,

I also thought that this was happening in profile2's hook for the user_register, which is quite logic after all. But sadly commenting this block was precisely what I meant by :

I looked into profile2 folders and files trying to comment parts related to the registration

... it still renders the $form[profile_driver] when I print_r($form) (I did clear the caches several times to make sure).

I was going to write that I had no clue where it could be if not here, but I just found out that it is actually in the profile2_regpath module that attached the fields to the user_register_form. For the record, line 424 of profile2_regpath.module :

function profile2_regpath_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_register_form') {
    // Get profile2 profile types from current path.
    $url = drupal_parse_url($form['#action']);
    $path = explode('/', str_replace('/inscription', '', $url['path']));
    $path_key = end($path);
    $profile_types = profile2_regpath_get_profiles($path_key);
    // profile2_regpath_attach_profile_fields($form, $form_state, $form_id, $profile_types);
  }
}

Commenting out the last line as I did prevents the [profile_driver] key to load, but every behavior is withdrawn. I uncommented and tried modifying profile2_attach_form since it's the function responsible to the loading of the fields in the function that I commented above :

if($profile->type !== 'driver'){
        field_attach_form('profile2', $profile, $form['profile_' . $profile->type], $form_state);
    }

It attaches the profile to the user but none of its fields.

I'm trying for a few hours to figure out how to attach the fields after the submission or on user_insert but no success so far.

I'll update here once I found.

EDIT : I tried to field_attach_form on the submit handlers, but it doesn't work in the end; when I do so and dpm($form), I can see that the fields are indeed part of $form['profile_driver'], but after logging in with the new account the fields don't appear in the edit form, which leads me to think that I can't do such a thing on a handler.
Maybe I'm missing knowledge on the normal usage of handlers, but I don't see where to put the snippet to translate "Load the fields of the Profile2 before submitting the form" if not on the submit handler.
If anyone has a clue about that ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.