You are here

function field_group_remove_empty_display_groups in Field Group 7

Same name and namespace in other branches
  1. 8.3 field_group.module \field_group_remove_empty_display_groups()
  2. 8 field_group.module \field_group_remove_empty_display_groups()
  3. 7.2 field_group.module \field_group_remove_empty_display_groups()

Remove empty groups on entity display.

Parameters

array $element: The element to check the empty state.

array $groups: Array of group objects.

1 call to field_group_remove_empty_display_groups()
field_group_field_group_build_pre_render_alter in ./field_group.module
Implements hook_field_group_build_pre_render_alter().

File

./field_group.module, line 1240
Fieldgroup module.

Code

function field_group_remove_empty_display_groups(&$element, $groups) {
  $empty_child = TRUE;
  $empty_group = TRUE;

  // Loop through the children for current element.
  foreach (element_children($element) as $name) {

    // Descend if the child is a group.
    if (in_array($name, $groups)) {
      $empty_child = field_group_remove_empty_display_groups($element[$name], $groups);
      if (!$empty_child) {
        $empty_group = FALSE;
      }
    }
    elseif (!empty($element[$name]) && (!isset($element[$name]['#access']) || $element[$name]['#access'])) {
      $empty_group = FALSE;
    }
  }

  // Reset an empty group.
  if ($empty_group) {
    $element = NULL;
  }
  return $empty_group;
}