I have a custom form and I'm attaching some fields from a custom entity. I add my fields like this:
$skeleton = entity_create('registrations', array('type' => 'registrations'));
field_attach_form('registrations', $skeleton, $form, $form_state, NULL, array('field_name' => 'field_dietary_info'));
field_attach_form('registrations', $skeleton, $form, $form_state, NULL, array('field_name' => 'field_bluecard_number'));
where field_dietary_info is NOT in a field group, and field_bluecard_number IS in a field group. The problem is that field_bluecard_number never appears in the form.
If I add ONLY field_bluecard_number (while $form is empty), it will appear in its group. But if $form is not empty, any field in a group will not appear.
Using a process of elimination, I can get the field to appear if I comment out the following lines in field_group_fields_nest()
in field_group.module:
if (isset($element[$child_name]) && (!isset($element[$child_name]['#access']) || $element[$child_name]['#access'])) {
// If this is a group, we have to use a reference to keep the reference
// list intact (but if it is a field we don't mind).
$group_references[$parent_name][$child_name] = &$element[$child_name];
}
// The child has been copied to its parent: remove it from the root element.
unset($element[$child_name]);
It seems the unset is getting rid of it altogether...
Comments
Comment #1
tim.plunkettIt may just be coincidence, but I found a bug under different circumstances with the same code you mention.
Try the patch in #2212431: Field groups that contain only elements that use #markup are hidden and see if it has any effect.
Comment #2
simeMarking this outdated as it's been over 2 years and no reply to Tim's suggestion. Please open again if in error.