I noticed that when you add a field via the hook_field_extra_fields() to a field group, it will not show up inside this field group but pops out of it.
For that reason I created a small test module on a clean Drupal install to be sure. This is also the case for preprocess fields created with Display Suite.

Screenshots:
Field group admin
Rendered node

The code for the test module (fg.module):

function fg_field_extra_fields() {
  $extra['node']['article'] = array(
    'display' => array(
      'test_field' => array(
        'label' => t('Test field'),
        'description' => t('Test field'),
        'weight' => 0,
      ),
    ),
  );
  
  return $extra;
}

function fg_preprocess_node(&$vars) {
  $vars['content']['test_field'] = array(
    '#markup' => t('Test field'),
  );
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nils.destoop’s picture

Included is a patch that should fix it.
This is a major change in the fieldgroup rendering functionality, so we will only add it to branch 2.

nils.destoop’s picture

Status: Active » Needs review
nils.destoop’s picture

Status: Needs review » Needs work

Ignore the patch, new coming soon :)

nils.destoop’s picture

Status: Needs work » Needs review
FileSize
7.71 KB

The previous patch broke the forms. Included a new patch

Stalski’s picture

Please review this, fieldgroup lovers!

jover’s picture

FileSize
65.77 KB

I applied the patch and the fieldset now contains the extra field correctly, but everything appears twice as you can see on the screenshot...
Double output patch

Stalski’s picture

hmm we had too at first but it worked after a fix. I'll look into this with zuuper

nils.destoop’s picture

This should be better :). Vars was not given by reference after the refactoring for forms.

jover’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
32.7 KB

Great work! :-)
It works!

Stalski’s picture

Version: 7.x-1.1 » 7.x-2.x-dev

Looking good.
Switching to branch 2.

nils.destoop’s picture

Status: Reviewed & tested by the community » Fixed

The patch is now committed to 7.x-2.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

olofbokedal’s picture

Status: Closed (fixed) » Active

This doesn't work for me, using the latest 2.x-dev version.

The scenario is nothing special. A DS preprocess field that has been put in a div group with some other fields. The field gets it content from our_theme_preprocess_node() function.

I'm using custom display settings for Full content and Teaser.

If you need any more info or could point me in any direction to sort this bug out, please let me know.

howto’s picture

I confirm that version 7.x-2.x-dev doesn't work. Module field group still doesn't group extra fields.

dale386’s picture

Any word on when this patch will be integrated into dev?

nils.destoop’s picture

Assigned: Unassigned » nils.destoop
jover’s picture

I also confirm that newer versions are not working.
In production I'm still using a patched version (comment #8) of Field Group, the latest Field Group version at that time.
Since then, I tried to upgrade several times when new versions were coming out, but without success...

So I have a working (old) version in production which isn't updated since then...

nils.destoop’s picture

Status: Active » Closed (cannot reproduce)
FileSize
53.64 KB

I just tested this with the latest version of DS. Both my custom preprocess field, and ds preprocess field appear in the correct group. (see screenshot)
Closing this for the moment. Re-open with extra information, if it still occurs with latest version of DS.

DigitalFrontiersMedia’s picture

Status: Closed (cannot reproduce) » Active

I'm completely confused. I'm running into this same problem using horizontal tab items in the latest 7.x-1.x-dev (7.x-1.1+65-dev) of field_group and the latest dev version of DS (7.x-1.5+58-dev). Preprocess fields just dump outside the field groups.

I understand that the patch above is for 7.x-2.x but the project page for field_group says quite clearly "The 7.x-2.x branch will not be supported any longer...Note: Current changes are made in the 1 branch."

Which branch am I supposed to be using that incorporates fixes for these problems? If I need to switch to the 2.x branch, are there any upgrade path implications for my existing configuration?

nils.destoop’s picture

Currently, the 7.x-2.x branch is not yet merged with the 7.x-1.x branch. If you want the preprocess functions, you can apply following patch. http://drupal.org/files/fieldgroup-preprocess-1342878_0.patch

This patch is currently in 7.x-2.x, but will be merged to 7.x-1.x

DigitalFrontiersMedia’s picture

Hmmm... okay, well, I tried applying the patch against field_group-7.x-1.1+65-dev:

we11!w_pgt:~/public_html/pgt/sites/all/modules/field_group$ patch -p1 < fieldgroup-preprocess-1342878_0.patch
patching file field_group.module
Hunk #1 succeeded at 165 (offset -2 lines).
Hunk #2 succeeded at 230 (offset -2 lines).
Hunk #3 succeeded at 1203 (offset -10 lines).
Hunk #4 succeeded at 1696 (offset -2 lines).
Hunk #5 succeeded at 1760 (offset -2 lines).
Hunk #6 succeeded at 1776 (offset -2 lines).

But now none of my preprocess fields are rendered at all inside or outside of groups. They're just gone.

Any ideas why this might be?

DigitalFrontiersMedia’s picture

belay any response. Just saw a bug. Let me look at that before expending any energy on your part. thanks.

DigitalFrontiersMedia’s picture

Well, fixed my bug. Now DS preprocess fields are being rendered, but outside the groups. Worse still, it appears that something in the patch jacked up the js so Horizontal Tab Items aren't working:

Uncaught TypeError: Object #

has no method 'drupalGetSummary' horizontal-tabs.js:128
DigitalFrontiersMedia’s picture

Maybe I'm misunderstanding this issue. I'm not using the extra fields option by name. I'm adding a DS Custom Preprocess field which latches onto a variable in preprocess_node function. Is there a difference here in how it should group or not group this?

DigitalFrontiersMedia’s picture

Okay, I rewrote my code to match the fg.module. The test_field *IS* rendered in the right group, but I still get the javascript error:

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

when using Horizontal Tabs which essentially makes this useless. The code in the patch and its context is too complex for me to immediately grok how its interaction is killing the js. I'd really appreciate someone more intimate with the code taking a look.

One thing I can comment on is that when the patch is applied and you dpm a field, it's no longer field_X['und'][0]... It's field_X[0]... So this patch appears to be changing the field structures on fields it's not supposed to be messing with and in ways I don't think it should be. I mean, it shouldn't be deleting language parameters on the object should it? And if that's the case and it's not standard, then maybe the javascript is failing because the drupal method (drupalGetSummary) is not finding the object in the format that it's expecting?

Someone please help. My head hurts. :-)

DigitalFrontiersMedia’s picture

Just attaching a screenshot showing that "Test field" IS rendered, but horizontal tabs, they ain't:

horizontal tabs not showing up

DigitalFrontiersMedia’s picture

Here are two screenshots showing dpm's of field_product_line from hook_preprocess_node. As you can see one is structured as:

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

The other shows the structure as:

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

DigitalFrontiersMedia’s picture

Status: Active » Closed (fixed)

Since it appears the field *IS* actually rendering inside the correct group (the original problem) and the patch has been committed to the 2.x branch to be merged with the 1.x branch but the patch is killing horizontal tab display, I'm closing this thread and opening a new, related one regarding the now non-functional horizontal tabs.

DigitalFrontiersMedia’s picture

charlie-s’s picture

Is there any way to get this into 1.x?

The patch from #20 applied without error, although my fields are still outside of the horizontal tabs after clearing my cache and commenting out line 138 of horizontal-tabs.js where this.fieldset is not an object.

vlad.dancer’s picture

Patch #8 doesn't work for me.
Display Suite: 7.x-2.2
Fieldgroup: 7.x-1.1 (also tried 7.x-1.dev and 2 v too)
Did anyone resolve this issue?

olofbokedal’s picture

Status: Closed (fixed) » Active
FileSize
8.07 KB

Doesn't work for me either. As said in #30, the patch applies just fine, but it doesn't fix the issue.

I've created a content type with a field group and a preprocess field that I've put in a Feature.

Modules involved

  • Drupal core 7.22
  • Chaos tools 7.x-1.3
  • Display Suite 7.x-2.3
  • Features 7.x-2.0-rc1
  • Field Group 7.x-1.x-dev from 2013-May-16 (with patch from #20 applied)
  • Strongarm 7.x-2.0

Steps to reproduce

  1. Install Drupal using the Standard profile.
  2. Download the attached feature and enable it.
  3. Add $variables['preprocess_field'] = 'This is the preprocess field.'; to the preprocess_node function for the default theme. In my case, this was Bartik.
  4. Create a Preprocess test node with random values for Title and Body.
  5. View the node. The Title and Body will be located inside of the group. The preprocess field will be located outside of the group.
Stalski’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev

I'll move this to 7.x-1.x as we merged 2 into 1. Could anyone retest if the problem still occurs?

nils.destoop’s picture

Status: Active » Closed (fixed)

This should be fixed in latest release. There is only 1 bug left, #2049291: Wrong order of the fields

nils.destoop’s picture

Issue summary: View changes

Added screenshots

Jolidog’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

I'm still having this issue with a preprocess DS field not wanting to render inside a field_group. DS Code fields and DS Block fields both render fine inside a field_group.
Versions:
field_group 1.3
ds 2.6

To replicate, create a DS preprocess field, run hook_preprocess_node to add content to the field, place it inside a field_group and see it rendering outside.
Also note preprocess fields don't have all the markup around them, making me think they are not run trough the theme_field function, could this be related?

Thanks for your hard work!

drupix’s picture

#33 Worked for me.

Nicolas Bouteille’s picture

Same problem as mentioned in #35

emudojo’s picture

same as #35, I'll vote to re-open this

dxx’s picture

Hi,

same issue mentioned in #35 with 7.x-1.4 (fields added via Display Suite 7.x-2.6)

joey-santiago’s picture

It happens for me too on 7.x-2.6+29-dev :(

thanks!

Bart Vanhoutte’s picture

Same as #35, DS 7.x-2.6 & Field Group 7.x-1.4.

WillowDigit’s picture

Same as #35.

I can get a code field to embed in a field group correctly, but not a preprocess field.

MariaIoann’s picture

I had the same problem. Resolved it using the following code:

function fg_preprocess_node(&$vars) {
  $vars['content']['test_field'][0] = array(
    '#markup' => t('Test field'),
  );
}

Note the [0] index after the ['test_field'].

Now the preprocess field is rendered inside the appropriate field group.

ohthehugemanatee’s picture

Status: Active » Needs review
FileSize
896 bytes

This is the case for any fields defined in DS. It looks like this is because DS has a higher module weight than field_group, so it doesn't add the fields until AFTER field_group has added parent options to the form.

Attaching a patch which moves our form_alter()s so they happen after DS.

axooh’s picture

I applied path #44, but the preprocessor field is still rendered outside the field group.

le72’s picture

Same problem here.

rahmanimran’s picture

#43 worked for me, thanks man you saved my day

mkhamash’s picture

This is another issue on display suite module page for the same exact problem.

m.abdulqader’s picture

I applied path #44, but the preprocessor field is still rendered outside the field group.

Sampe for me.

Dom.’s picture

loopduplicate’s picture

Status: Needs review » Needs work
  1. +++ b/field_group.module
    @@ -2167,3 +2167,19 @@ function _field_group_get_default_formatter_settings($format_type, $mode) {
    +    if ($hook = 'form_alter' && isset($implementations['field_group'])) {
    

    Accidental assignment here; $hook = 'form_alter' will always evaluate to TRUE.

  2. +++ b/field_group.module
    @@ -2167,3 +2167,19 @@ function _field_group_get_default_formatter_settings($format_type, $mode) {
    \ No newline at end of file
    

    Needs a line break at the end of the file.

This probably also needs a test.

esolitos’s picture

Status: Needs work » Needs review
FileSize
889 bytes

Applied suggested fixes from #51, missing still tests 'tho.

rackberg’s picture

Just tried the solution posted in comment #43.

For me it works as expected. No need to create a patch.

rimen’s picture

Another solution is use hook_node_view_alter instead preproces to embed custom (extra) fields
All works as designed

loopduplicate’s picture

Thanks for the tip, @rimen . There's also hook_entity_view_alter() for other entity types.

loopduplicate’s picture

Assigned: nils.destoop » Unassigned
Issue tags: +Needs tests
Chris Matthews’s picture

Status: Needs review » Closed (works as designed)