- Issue created by @jeremypeter
- 🇨🇭Switzerland grumpy74 Geneva, CH 🇨🇭
@jeremypeter, did you try to add your fields alterations using the form['#after_build'] callback instead ?
In my case, I don't have an existing fieldgroup, otherwise I create 2 tabs (one for the fields of the paragraph and one for the behavior plugins) and the only way to make the alterations to work is using the after_build callback (as layout paragraph creates the behavior plugins on the #process callback, which is called after the form_alter hook).
Using after_build will maybe spare you from managing a custom submit and a variables reassignment ?! I let you try in your fieldgroup context though.
Here is my example if anyone wants to do so creating tabs dynamically :
function yourmodulename_form_layout_paragraphs_component_form_alter(array &$form, FormStateInterface &$form_state) { // Create tabs for content fields and paragraph behavior for a better UI/UX. $form['tabs'] = array( '#type' => 'horizontal_tabs', ); $form['tab_content'] = [ '#type' => 'details', '#group' => 'tabs', '#title' => 'Content', ]; $form['tab_behaviours'] = [ '#type' => 'details', '#group' => 'tabs', '#title' => t('Settings'), ]; // Content tab. // Add paragraphs fields in the content tab. $avoidedFieldsNames = ['behavior_plugins', 'actions', 'tabs', 'tab_content', 'tab_behaviours']; foreach (Element::children($form) as $field) { if(!in_array($field, $avoidedFieldsNames)) { $formField = $form[$field]; $form['tab_content'][$field] = $formField; unset($form[$field]); } } // BEHAVIOUR TAB // Add after build custom method to set custom behaviour tab $form['behavior_plugins']['#type'] = 'container'; $form['#after_build'][] = 'yourmodulename_behavior_plugins_form_after_build'; } /** * Form after build. * * As the Behavior Plugins are created by Layout paragraphs using the "#process" * callback system, we need to operate our final alterations on the form on the * "#after_build" callback. * */ function yourmodulename_behavior_plugins_form_after_build($form, &$form_state) { // Add custom behaviour tab with duplicate fields from original behavior plugins fields. $form['tab_behaviours']['behavior_plugins'] = $form['behavior_plugins']; $form['tab_behaviours']['behavior_plugins']['#group'] = 'tabs'; $form['behavior_plugins']['#group'] = 'tabs'; // hidde original behavior_plugins fields. $form['behavior_plugins']['#attributes']['class'][] = 'hidden'; // horizontal tabs library. $form['#attached']['library'][] = 'field_group/formatter.horizontal_tabs'; return $form; }