You are here

function field_group_hide_field_groups in Field Group 7

Same name in this branch
  1. 7 field_group.api.php \field_group_hide_field_groups()
  2. 7 field_group.module \field_group_hide_field_groups()

Hides field groups including children in a render array.

Parameters

array $element: A render array. Can be a form, node, user, ...

array $group_names: An array of field group names that should be hidden.

File

./field_group.module, line 2178
Fieldgroup module.

Code

function field_group_hide_field_groups(&$element, $group_names) {
  foreach ($group_names as $group_name) {
    if (isset($element['#fieldgroups'][$group_name]) && isset($element['#group_children'])) {

      // Hide the field group.
      $element['#fieldgroups'][$group_name]->format_type = 'hidden';

      // Hide the elements inside the field group.
      $sub_groups = array();
      foreach (array_keys($element['#group_children'], $group_name) as $field_name) {
        if (isset($element['#fieldgroups'][$field_name])) {
          $sub_groups[] = $field_name;
        }
        else {
          $element[$field_name]['#access'] = FALSE;
        }
      }
      field_group_hide_field_groups($element, $sub_groups);
    }
  }
}