Last active
September 30, 2015 19:29
-
-
Save marioangulo/daa336a2a4b13fb26e08 to your computer and use it in GitHub Desktop.
Drupal Hide Group/Sub Groups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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