- 🇬🇧United Kingdom lind101
For those landing here looking for a way to add #states to field_groups in a more generic way via traditional form_alter_hooks, the below helper hook works well.
/** * Implements hook_field_group_form_process(). */ function my_module_field_group_form_process(array &$element, &$group, &$complete_form) { /** * Provides a generic way for assigning Form API #states to field group elements * * @usage - In a from_alter hook the Group object can be added to include a form_api_states property, * which is picked up here and applied to the field group element * @code * $form['#fieldgroups']['group_my_group']->form_api_states = [ * 'visible' => [ * ':input[name^="my_field_name"]' => ['checked' => TRUE], * ] * ]; * @endcode */ if (isset($group->form_api_states) && is_array($group->form_api_states) && !isset($element['#states'])) { $element['#states'] = $group->form_api_states; } }
- 🇪🇨Ecuador dmezquia UTC-5
The hook
hook_field_group_form_process
works ok for me too.