You are here

function field_group_attach_groups in Field Group 8.3

Same name and namespace in other branches
  1. 8 field_group.module \field_group_attach_groups()
  2. 7.2 field_group.module \field_group_attach_groups()
  3. 7 field_group.module \field_group_attach_groups()

Attach groups to the (form) build.

Parameters

array $element: The part of the form.

array $context: The contextual information.

5 calls to field_group_attach_groups()
field_group_entity_view_alter in ./field_group.module
Implements hook_entity_view_alter().
field_group_form_alter in ./field_group.module
Implements hook_form_alter().
field_group_form_layout_builder_update_block_alter in ./field_group.module
Implements hook_form_layout_builder_update_block_alter().
field_group_form_media_library_add_form_upload_alter in ./field_group.module
Implements hook_form_media_library_add_form_upload_alter().
field_group_inline_entity_form_entity_form_alter in ./field_group.module
Implements hook_inline_entity_form_entity_form_alter().

File

./field_group.module, line 538
Allows administrators to attach field groups.

Code

function field_group_attach_groups(&$element, $context) {
  if ($context['mode'] == '_custom') {
    return;
  }
  $entity_type = $context['entity_type'];
  $bundle = $context['bundle'];
  $mode = $context['mode'];
  $display_context = $context['display_context'];
  $element['#fieldgroups'] = field_group_info_groups($entity_type, $bundle, $display_context, $mode);

  // Create a lookup array.
  $group_children = [];
  foreach ($element['#fieldgroups'] as $group_name => $group) {
    if (!empty($group->children)) {
      foreach ($group->children as $child) {
        $group_children[$child] = $group_name;
      }
    }
  }
  $element['#group_children'] = $group_children;
  $element['#entity_type'] = $entity_type;
}