You are here

function field_group_form_alter in Field Group 8

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

Implements hook_form_alter().

File

./field_group.module, line 171
Allows administrators to attach custom fields to fieldable types.

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 EntityFormDisplayInterface $form_display
     */
    $storage = $form_state
      ->getStorage();
    if (!empty($storage['form_display'])) {
      $form_display = $storage['form_display'];
      $entity = $form_object
        ->getEntity();
      $context = array(
        '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['#pre_render'][] = 'field_group_form_pre_render';
    }
  }
}