Commit 2cf89719 authored by Jo Fitzgerald's avatar Jo Fitzgerald Committed by Marco Fernandes
Browse files

Issue #3096002 by jofitz: Support Field Groups

parent 0ed14c01
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -573,6 +573,24 @@ function gutenberg_form_node_form_alter(&$form, FormStateInterface $form_state)
    }
  }

  $gutenberg_field = $text_fields[0];

  // If any field groups do not have a parent then set the parent as metabox_fields.
  if (!empty($form['#fieldgroups'])) {
    foreach ($form['#fieldgroups'] as &$group) {
      if (empty($group->parent_name)) {
        $group->parent_name = 'metabox_fields';
        $metabox_has_fields = TRUE;
      }
      // If the field with Gutenberg applied to it is in a field group then remove it.
      foreach ($group->children as $key => $child) {
        if ($child == $gutenberg_field) {
          unset($group->children[$key]);
        }
      }
    }
  }

  $form['#after_build'][] = 'gutenberg_form_node_form_details_after_build';
  $form['#fields_with_details'] = $fields_with_details;

@@ -972,3 +990,17 @@ function _gutenberg_is_gutenberg_enabled(EntityInterface $entity = NULL) {

  return (bool) $config->get($node_type . '_enable_full');
}

/**
 * Implements hook_module_implements_alter().
 */
function gutenberg_module_implements_alter(&$implementations, $hook) {
  switch ($hook) {
    // Move our hook_form_alter() implementation to the end of the list.
    case 'form_alter':
      $group = $implementations['gutenberg'];
      unset($implementations['gutenberg']);
      $implementations['gutenberg'] = $group;
      break;
  }
}