function field_group_remove_empty_form_groups in Field Group 7.2
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 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 1043 - Fieldgroup module.
Code
function field_group_remove_empty_form_groups($name, &$element, $groups, &$form_groups, $entity) {
$exceptions = array(
'user__account',
'comment__author',
);
$children = element_children($element);
$hasChildren = FALSE;
if (count($children)) {
foreach ($children as $childname) {
if (in_array($childname, $groups)) {
field_group_remove_empty_form_groups($childname, $element[$childname], $groups, $form_groups, $entity);
}
$exception = $entity . '__' . $childname;
$hasChildren = $hasChildren ? TRUE : isset($element[$childname]['#type']) || in_array($exception, $exceptions);
}
}
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;
}
}