diff --git i/field_group.module w/field_group.module index 772405d..357a917 100644 --- i/field_group.module +++ w/field_group.module @@ -2025,6 +2025,15 @@ function field_group_fields_nest(&$element, &$vars = NULL) { // Construct own weight, as some fields (for example preprocess fields) don't have weight set. $element[$group_name] = array(); $group_references[$group_name] = &$element[$group_name]; + // Get group parents + $parents = array(); + $current_group = $group; + while (!empty($current_group)) { + array_unshift($parents, $current_group->group_name); + $current_group = $element['#fieldgroups'][$current_group->parent_name]; + } + $group_references[$group_name]['#array_parents'] = $parents; + $element['#fieldgroups'][$group_name]->array_parents = $parents; } } @@ -2075,6 +2084,19 @@ function field_group_fields_nest(&$element, &$vars = NULL) { // list intact (but if it is a field we don't mind). $group_references[$parent_name][$child_name] = &$element[$child_name]; $group_references[$parent_name]['#weight'] = $element['#fieldgroups'][$parent_name]->weight; + // Set #array_parents of group child element + $group_child = &$group_references[$parent_name][$child_name]; + $group_parents = $group_references[$parent_name]['#array_parents']; + if (isset($group_child['#array_parents'])) { + // array_unique in case it's already prepended ... somehow + $group_child['#array_parents'] = array_unique(array_merge($group_parents, $group_child['#array_parents'])); + } + // And recursively for element's children + foreach (_element_children_recursive_ref($group_child) as &$group_child_child) { + if (isset($group_child_child['#array_parents'])) { + $group_child_child['#array_parents'] = array_unique(array_merge($group_parents, $group_child['#array_parents'])); + } + } } // The child has been copied to its parent: remove it from the root element. @@ -2239,3 +2261,23 @@ function _field_group_get_default_formatter_settings($format_type, $mode) { ); } + +/** + * Recursive element_children, returns children by reference + */ +function _element_children_recursive_ref(&$element) +{ + $results = array(); + $children = element_children($element); + foreach($children as $key) + { + $child = &$element[$key]; + if(is_array($child)) + { + $results[] = &$child; + $results = array_merge($results, _element_children_recursive_ref($child)); + } + unset($child); + } + return $results; +}