You are here

function field_group_form_alter in Field Group 8.3

Same name and namespace in other branches
  1. 8 field_group.module \field_group_form_alter()

Implements hook_form_alter().

File

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

Code

function field_group_form_alter(array &$form, FormStateInterface $form_state) {
  $form_object = $form_state
    ->getFormObject();
  if ($form_object instanceof ContentEntityFormInterface && !$form_object instanceof ConfirmFormInterface) {

    /**
     * @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display
     */
    $storage = $form_state
      ->getStorage();
    if (!empty($storage['form_display'])) {
      $form_display = $storage['form_display'];
      $entity = $form_object
        ->getEntity();
      $context = [
        'entity_type' => $entity
          ->getEntityTypeId(),
        'bundle' => $entity
          ->bundle(),
        'entity' => $entity,
        'context' => 'form',
        'display_context' => 'form',
        'mode' => $form_display
          ->getMode(),
      ];
      field_group_attach_groups($form, $context);
      $form['#process'][] = [
        FormatterHelper::class,
        'formProcess',
      ];
    }
  }
}