On the user edit form, the "User name and password" ends up being a container that holds a lot of things that I would like to split up to display nicer. This is the code I have in the form_alter:
// Pull out the account container pieces and move them.
$form['username'] = $form['account']['name'];
$form['username']['#group'] = 'group_name_and_email';
$form['#group_children']['username'] = 'group_name_and_email';
$form['#fieldgroups']['group_name_and_email']->children[] = 'username';
unset($form['account']['name']);
$form['email'] = $form['account']['mail'];
$form['email']['#group'] = 'group_name_and_email';
$form['#group_children']['email'] = 'group_name_and_email';
$form['#fieldgroups']['group_name_and_email']->children[] = 'email';
unset($form['account']['mail']);
$form['password'] = $form['account']['pass'];
$form['password']['#group'] = 'group_password';
$form['#group_children']['password'] = 'group_password';
$form['#fieldgroups']['group_password']->children[] = 'password';
unset($form['account']['pass']);
$form['notify'] = $form['account']['notify'];
$form['notify']['#group'] = 'group_administration';
$form['#group_children']['notify'] = 'group_administration';
$form['#fieldgroups']['group_administration']->children[] = 'notify';
unset($form['account']['notify']);
$form['roles'] = $form['account']['roles'];
$form['roles']['#group'] = 'group_administration';
$form['#group_children']['roles'] = 'group_administration';
$form['#fieldgroups']['group_administration']->children[] = 'roles';
unset($form['account']['roles']);
$form['status'] = $form['account']['status'];
$form['status']['#group'] = 'group_administration';
$form['#group_children']['status'] = 'group_administration';
$form['#fieldgroups']['group_administration']->children[] = 'status';
unset($form['account']['status']);
Out of all of these, the only one that behaves is the username. The rest just plop on the form in one spot outside of all the fieldgroups. I found #2980710: Move field programatically to field group (how to) and what it says to do there is what I've done. I've checked out everything in xdebug and can't see any difference in the render array between the one that works and the rest that don't.
Any ideas?
Comments
Comment #2
michelleI've also discovered that my moved form fields break the form saving so this may not be viable at all. I'm thinking this is a won't fix as it's probably not an issue with Field Group but rather the fact that so much stuff is stuffed into that "username and password" pseudo field. I'll leave it open for now in case anyone has input but I understand if the maintainer won't fixes it.
Comment #3
phjouTrying to also move a field programmatically into a field group. I couldn't achieve it.
It seems like it was done using hook_field_group_build_pre_render_alter before but that function is not called on the latest version 8.x-3.
I am currently trying using hook_field_group_form_process_build because this one is called, I found it because of this issue. We'll see if I can succeed #3100893: hook_field_group_build_pre_render_alter() is not called since 3.x
EDIT, ok I managed to do it like this: