This thread is a spin-off of #1342878: Preprocessor (extra) fields do not show inside field group. Background details on this issue can be found there.

Hunk #4 of http://drupal.org/files/fieldgroup-preprocess-1342878_0.patch kills Horizontal Tabs by somehow altering the structure of fields in ways it shouldn't. When it does so, the method drupalGetSummary used in horizontal-tabs.js fails due to the structure change, I believe:
Uncaught TypeError: Object # has no method 'drupalGetSummary' horizontal-tabs.js:128

A dpm of a field from hook_preprocess_node will normally show a field structure as:

field_X['und'][0]...
(field_group-7.x-1.1+65-dev WITHOUT fieldgroup-preprocess-1342878_0.patch; horizontal tabs still work at this stage)

After applying the patch, the structure is missing the langcode array:

field_X[0]...
(field_group-7.x-1.1+65-dev WITH fieldgroup-preprocess-1342878_0.patch; horizontal tabs are completely broken after applying patch)

The result is field source code that is rendered correctly but not displayed correctly--no horizontal tabs and no dynamic interaction to actually open the tabs and view the field data. Thus, since no horizontal tabs are actually provided after this patch, marking this as 'major' priority.

If the patch is applied without Hunk #4, horizontal tabs still work but fields are not rendered properly. Hunk #4:

@@ -1659,45 +1698,59 @@ function field_group_attach_groups(&$element, $view_mode, $form_state = array())
   }
   $element['#group_children'] = $group_children;
 
-  // Add a pre render callback.
-  // This is needed since process seems too early for the front view modes.
-  // This is main bottleneck in field_group. By using this, we can't process
-  // our added groups in a normal way, resulting in early creation of vertical
-  // tabs, horizontal tabs and multipages.
-  $element['#pre_render'][] = 'field_group_build_pre_render';
+}
 
+/**
+ * Pre render callback for rendering groups.
+ * @see field_group_field_attach_form
+ * @param $element Form that is beïng rendered.
+ */
+function field_group_form_pre_render(&$element) {
+  return field_group_build_entity_groups($element, 'form');
 }
 
 /**
- * Process/ Pre-render callback.
+ * Preprocess/ Pre-render callback.
  *
- * Depending on whether it is a form build or content build.
- * Form api go through more than a regular build. #process is
- * needed here, where #pre_render is ideal for the regular array.
- * @see field_group_attach_groups()
+ * @see field_group_form_pre_render()
+ * @see field_group_theme_registry_alter
  * @see field_group_fields_nest()
- * @param $element Form element
+ * @param $vars preprocess vars or form element
+ * @param $type The type of object beïng rendered
  * @return $element Array with re-arranged fields in forms.
  */
-function field_group_build_pre_render($element) {
+function field_group_build_entity_groups(&$vars, $type) {
 
-  // Skip the nesting and field_group functions if no fieldgroups.
-  // This could be because you don't see them in the UI or programmatically.
-  if (empty($element['#fieldgroups'])) {
-    return $element;
+  if ($type == 'form') {
+    $element = &$vars;
+    $nest_vars = NULL;
+  }
+  else {
+    $element = &$vars['elements'];
+    $nest_vars = &$vars;
   }
 
-  // Merge our #fieldgroups with #groups to avoid conflicts on fieldset types.
-  $element['#groups'] = array_merge($element['#groups'], $element['#fieldgroups']);
+  if (!isset($element['#groups'])) {
+    return $element;
+  }
 
   // Nest the fields in the corresponding field groups.
-  field_group_fields_nest($element);
+  field_group_fields_nest($element, $nest_vars);
 
   // Allow others to alter the pre_rendered build.
   drupal_alter('field_group_build_pre_render', $element);
 
-  return $element;
+  // Return the element on forms.
+  if ($type == 'form') {
+    return $element;
+  }
 
+  // Put groups inside content if we are rendering an entity_view.
+  foreach ($element['#groups'] as $group) {
+    if (!empty($element[$group->group_name])) {
+      $vars['content'][$group->group_name] = $element[$group->group_name];
+    }
+  }
 }
 
 /**

PLEASE help! I'm not familiar enough with this area to understand why langcode is being dropped.

No Horizontal Tabs :-( :
no h-tabs

CommentFileSizeAuthor
no-h-tabs.png94.39 KBDigitalFrontiersMedia
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DigitalFrontiersMedia’s picture

Okay, stupidest fix ever, but all I did was comment out line 128 of horizontal-tabs.js and the tabs are working again. No apparent mal side effects. But surely that code had some sort of purpose?

Uncaught TypeError: Object # has no method 'drupalGetSummary' horizontal-tabs.js:128

I'd like someone to verify what it's for and come up with a proper solution.

charlie-s’s picture

My js error was on line 138, so methinks that I patched a different version of field_group than you did. However, the patch did apply without error.

Regardless, my preprocess fields added via Display Suite are still sitting where they were before – outside of the fieldgroup :(

Jose Reyero’s picture

The problem happens when used without a form because of missing form.js library.

You can fix it adding this anywhere on your code:

drupal_add_js('misc/form.js');
Stalski’s picture

Status: Active » Closed (cannot reproduce)

The fix is correct. Usually as soon as a fieldgroup is present, the form.js will be included.

I must say, the initial issue is hard to reproduce, no success there at all.
Closing this issue, since the javascript is fixed in another issue. Most things are outdated I think. You can reopen the issue if the problems still occurs.