I want to hide some profile (previously profile2) fields from registration page. That should be easy, just hook_form_alter and:

$form['profile_additional']['field_sth_sth']['#access'] = FALSE;

But for the life of me I can't find whole ['profile_additional'] element, only standard registration form elements. How to access profile form on registration page from this hook?

 

(BTW setting this field as invisible works only for "customized for: account" part, not for registration page).

Accepted answer

Looks like this fix works only for the registration profile, not user edit profile, which renders profile module pretty useless.

The culprit is here, on line 500 of file profile.module:

function profile_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'form_alter' && isset($implementations['profile'])) {
    $group = $implementations['profile'];
    unset($implementations['profile']);
    $implementations['profile'] = $group;
  }
}

It forces execution of profile_form_user_register_form_alter() to be the last on the list of implementations. Hence one cannot alter user profile, since there are no data yet, at the time of calling mymodule_form_alter().

I've commented out contents of this function and now profiles work as exepected...

Comments

Oh, well, that's kinda embarrassing. Profile module uses hook_user_register_form_alter to attach its fields. But it was called after mine module (alphabetically), so I couldn't see those fields at the time of function call.

Changed module weight, cleared cache and it works.

Looks like this fix works only for the registration profile, not user edit profile, which renders profile module pretty useless.

The culprit is here, on line 500 of file profile.module:

function profile_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'form_alter' && isset($implementations['profile'])) {
    $group = $implementations['profile'];
    unset($implementations['profile']);
    $implementations['profile'] = $group;
  }
}

It forces execution of profile_form_user_register_form_alter() to be the last on the list of implementations. Hence one cannot alter user profile, since there are no data yet, at the time of calling mymodule_form_alter().

I've commented out contents of this function and now profiles work as exepected...