function field_group_field_layout_fields_nest in Field Group 8.3
Nests all the fields in the field groups.
Ror entity display elements managed by field layout.
Parameters
array $element:
$vars:
$context:
1 call to field_group_field_layout_fields_nest()
- field_group_build_entity_groups in ./
field_group.module - Pre-render callback for entity views.
File
- ./
field_group.module, line 740 - Allows administrators to attach field groups.
Code
function field_group_field_layout_fields_nest(array &$element, &$vars = NULL, $context = NULL) {
// Create all groups and keep a flat list of references to these groups.
$group_references = [];
foreach ($element['#fieldgroups'] as $group_name => $group) {
// Construct own weight, as some fields (for example preprocess fields)
// don't have weight set.
if (!isset($element[$group_name])) {
$element[$group_name] = [];
}
$group_references[$group_name] =& $element[$group_name];
}
// Loop through all children looking for those that are supposed to be
// in groups, and insert placeholder element for the new group field in the
// correct location within the form structure.
$element_clone = [];
foreach (Element::children($element['_field_layout']) as $region_name) {
foreach (Element::children($element['_field_layout'][$region_name]) as $child_name) {
$element_clone['_field_layout'][$region_name][$child_name] = $element['_field_layout'][$region_name][$child_name];
// If this element is in a group, create the placeholder element.
if (isset($element['_field_layout'][$region_name]['#group_children'][$child_name])) {
$element_clone['_field_layout'][$region_name][$element['#group_children'][$child_name]] = [];
}
}
}
$element = array_merge($element_clone, $element);
// Move all children to their parents. Use the flat list of references for
// direct access as we don't know where in the root_element hierarchy the
// parent currently is situated.
foreach ($element['#group_children'] as $child_name => $group_name) {
$region = $element['#fieldgroups'][$group_name]->region;
// If not a group, check the content variable for empty field.
$key = field_group_get_content_element_key($context);
if (!isset($element['#fieldgroups'][$child_name]) && isset($vars[$key]['_field_layout'][$region][$child_name])) {
// ECK marks his default properties as printed, while it is not printed yet.
if ($context === 'eck_entity' && !empty($vars[$key]['_field_layout'][$region][$child_name]['#printed'])) {
$vars[$key]['_field_layout'][$region][$child_name]['#printed'] = FALSE;
}
$group_references[$group_name][$child_name] = $vars[$key]['_field_layout'][$region][$child_name];
unset($vars[$key]['_field_layout'][$region][$child_name]);
}
else {
$group_references[$group_name][$child_name] =& $element[$child_name];
unset($element[$child_name]);
}
}
// Bring extra element wrappers to achieve a grouping of fields.
// This will mainly be prefix and suffix altering.
foreach ($element['#fieldgroups'] as $group_name => $group) {
field_group_pre_render($group_references[$group_name], $group, $element);
}
}