How to hide Field Groups in Drupal 7, the right way

There are times when you need to manipulate a form via hook_form_alter in Drupal, and you may need to hide/show fields depending on some criteria.

You can hide a single field using something like $form['field_name']['#type'] = 'hidden';.

But, what if you’re using the ‘field_group’ module and you want to hide a whole group? Well, you can use the function field_group_hide_field_groups(). It receives two parameters, $form, and an array of group names to hide.


function MODULE_form_form_id_alter(&$form, &$form_state, $form_id) {
$groups_to_hide = [
field_group_hide_field_groups($form, $groups_to_hide);


So you don’t have to hide field by field anymore!

Do you need some help?

Let's get started. Tell us a little about yourself and your organization
and we can start a conversation about your needs and our capabilities.
Tagged: ,

Related Posts