You are here

function _field_group_is_empty_element in Field Group 7

Determine if an element has non-empty children.

1 call to _field_group_is_empty_element()
field_group_remove_empty_form_groups in ./field_group.module
Remove empty groups on forms.

File

./field_group.module, line 1199
Fieldgroup module.

Code

function _field_group_is_empty_element($element, $entity, $childname, $groups) {
  $exceptions = array(
    'user__account',
    'comment__author',
  );
  $exception = $entity . '__' . $childname;
  if (in_array($exception, $exceptions)) {
    return TRUE;
  }
  if (isset($element[$childname]['#type']) || isset($element[$childname]['#markup']) || isset($element[$childname]['#prefix']) || isset($element[$childname]['#suffix'])) {
    return TRUE;
  }

  // Prevent a double recursive loop (groups are already recursive looped in field_group_remove_empty_form_groups.
  if (in_array($childname, $groups)) {
    return FALSE;
  }
  $children = element_children($element[$childname]);
  foreach ($children as $child) {
    if (_field_group_is_empty_element($element[$childname], $entity, $child, $groups)) {
      return TRUE;
    }
  }
  return FALSE;
}