function field_group_remove_empty_form_groups in Field Group 7
Same name and namespace in other branches
- 8.3 field_group.module \field_group_remove_empty_form_groups()
- 8 field_group.module \field_group_remove_empty_form_groups()
- 7.2 field_group.module \field_group_remove_empty_form_groups()
Remove empty groups on forms.
Parameters
String $parent_name: The name of the element.
array $element: The element to check the empty state.
array $groups: Array of group objects.
1 call to field_group_remove_empty_form_groups()
File
- ./
field_group.module, line 1160 - Fieldgroup module.
Code
function field_group_remove_empty_form_groups($name, &$element, $groups, &$form_groups, $entity) {
$children = element_children($element);
$hasChildren = FALSE;
if (count($children)) {
foreach ($children as $childname) {
if (in_array($childname, $groups, TRUE)) {
field_group_remove_empty_form_groups($childname, $element[$childname], $groups, $form_groups, $entity);
}
$hasChildren = $hasChildren ? TRUE : _field_group_is_empty_element($element, $entity, $childname, $groups);
}
}
if (!$hasChildren) {
// Remove empty elements from the #groups.
if (empty($element) && isset($form_groups[$name]) && !is_array($form_groups[$name])) {
foreach ($form_groups as $group_name => $group) {
if (isset($group->children)) {
$group_children = array_flip($group->children);
if (isset($group_children[$name])) {
unset($form_groups[$group_name]->children[$group_children[$name]]);
}
}
}
}
$element['#access'] = FALSE;
}
}