Skip to content

Instantly share code, notes, and snippets.

@marioangulo
Last active September 30, 2015 19:29
Show Gist options
  • Save marioangulo/daa336a2a4b13fb26e08 to your computer and use it in GitHub Desktop.
Save marioangulo/daa336a2a4b13fb26e08 to your computer and use it in GitHub Desktop.
Drupal Hide Group/Sub Groups
<?php
/**
* Helper function to hide group and sub groups from a form.
*
* @param $form
* Reference to a nested array of form elements that comprise the form.
* @param $group_names
* Array containing the names of the groups you want to hide.
*/
function field_group_hide_field_groups(&$form, $group_names) {
foreach ($group_names as $group_name) {
if (isset($form['#fieldgroups'][$group_name]) && isset($form['#group_children'])) {
$form['#fieldgroups'][$group_name]->format_type = 'hidden';
foreach (array_keys($form['#group_children'], $group_name) as $field_name) {
if (isset($form['#fieldgroups'][$field_name])) {
$sub_groups[] = $field_name;
} else {
$form[$field_name]['#access'] = FALSE;
}
}
if(isset($sub_groups)) {
field_group_hide_field_groups($form, $sub_groups);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment