Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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:
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'),
);
}
Comments
Comment #1
nils.destoop CreditAttribution: nils.destoop commentedIncluded 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.
Comment #2
nils.destoop CreditAttribution: nils.destoop commentedComment #3
nils.destoop CreditAttribution: nils.destoop commentedIgnore the patch, new coming soon :)
Comment #4
nils.destoop CreditAttribution: nils.destoop commentedThe previous patch broke the forms. Included a new patch
Comment #5
Stalski CreditAttribution: Stalski commentedPlease review this, fieldgroup lovers!
Comment #6
joverI applied the patch and the fieldset now contains the extra field correctly, but everything appears twice as you can see on the screenshot...
Comment #7
Stalski CreditAttribution: Stalski commentedhmm we had too at first but it worked after a fix. I'll look into this with zuuper
Comment #8
nils.destoop CreditAttribution: nils.destoop commentedThis should be better :). Vars was not given by reference after the refactoring for forms.
Comment #9
joverGreat work! :-)
Comment #10
Stalski CreditAttribution: Stalski commentedLooking good.
Switching to branch 2.
Comment #11
nils.destoop CreditAttribution: nils.destoop commentedThe patch is now committed to 7.x-2.x
Comment #13
olofbokedal CreditAttribution: olofbokedal commentedThis 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.
Comment #14
howto CreditAttribution: howto commentedI confirm that version 7.x-2.x-dev doesn't work. Module field group still doesn't group extra fields.
Comment #15
dale386 CreditAttribution: dale386 commentedAny word on when this patch will be integrated into dev?
Comment #16
nils.destoop CreditAttribution: nils.destoop commentedComment #17
joverI 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...
Comment #18
nils.destoop CreditAttribution: nils.destoop commentedI 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.
Comment #19
DigitalFrontiersMediaI'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?
Comment #20
nils.destoop CreditAttribution: nils.destoop commentedCurrently, 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
Comment #21
DigitalFrontiersMediaHmmm... 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?
Comment #22
DigitalFrontiersMediabelay any response. Just saw a bug. Let me look at that before expending any energy on your part. thanks.
Comment #23
DigitalFrontiersMediaWell, 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:128Comment #24
DigitalFrontiersMediaMaybe 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?
Comment #25
DigitalFrontiersMediaOkay, 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. :-)
Comment #26
DigitalFrontiersMediaJust attaching a screenshot showing that "Test field" IS rendered, but horizontal tabs, they ain't:
Comment #27
DigitalFrontiersMediaHere 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)
Comment #28
DigitalFrontiersMediaSince 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.
Comment #29
DigitalFrontiersMediaFor those playing along at home, the spin-off thread is #1778752: Patch for Correct Placement of Display Suite Preprocessor (extra) Fields within Groups Breaks Horizontal Tabs Javascript.
Comment #30
charlie-s CreditAttribution: charlie-s commentedIs 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.Comment #31
vlad.dancerPatch #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?
Comment #32
olofbokedal CreditAttribution: olofbokedal commentedDoesn'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
Steps to reproduce
$variables['preprocess_field'] = 'This is the preprocess field.';
to the preprocess_node function for the default theme. In my case, this was Bartik.Comment #33
Stalski CreditAttribution: Stalski commentedI'll move this to 7.x-1.x as we merged 2 into 1. Could anyone retest if the problem still occurs?
Comment #34
nils.destoop CreditAttribution: nils.destoop commentedThis should be fixed in latest release. There is only 1 bug left, #2049291: Wrong order of the fields
Comment #34.0
nils.destoop CreditAttribution: nils.destoop commentedAdded screenshots
Comment #35
Jolidog CreditAttribution: Jolidog commentedI'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!
Comment #36
drupix#33 Worked for me.
Comment #37
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedSame problem as mentioned in #35
Comment #38
emudojo CreditAttribution: emudojo commentedsame as #35, I'll vote to re-open this
Comment #39
dxx CreditAttribution: dxx commentedHi,
same issue mentioned in #35 with 7.x-1.4 (fields added via Display Suite 7.x-2.6)
Comment #40
joey-santiago CreditAttribution: joey-santiago commentedIt happens for me too on 7.x-2.6+29-dev :(
thanks!
Comment #41
Bart Vanhoutte CreditAttribution: Bart Vanhoutte commentedSame as #35, DS 7.x-2.6 & Field Group 7.x-1.4.
Comment #42
WillowDigit CreditAttribution: WillowDigit commentedSame as #35.
I can get a code field to embed in a field group correctly, but not a preprocess field.
Comment #43
MariaIoann CreditAttribution: MariaIoann commentedI had the same problem. Resolved it using the following code:
Note the [0] index after the ['test_field'].
Now the preprocess field is rendered inside the appropriate field group.
Comment #44
ohthehugemanatee CreditAttribution: ohthehugemanatee commentedThis 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.
Comment #45
axooh CreditAttribution: axooh commentedI applied path #44, but the preprocessor field is still rendered outside the field group.
Comment #46
le72Same problem here.
Comment #47
rahmanimran CreditAttribution: rahmanimran commented#43 worked for me, thanks man you saved my day
Comment #48
mkhamash CreditAttribution: mkhamash commentedThis is another issue on display suite module page for the same exact problem.
Comment #49
m.abdulqader CreditAttribution: m.abdulqader commentedSampe for me.
Comment #50
Dom. CreditAttribution: Dom. as a volunteer commentedPatch on #1452198: Preprocess fields completely fail with fieldgroups fixes issue for me.
Comment #51
loopduplicateAccidental assignment here; $hook = 'form_alter' will always evaluate to TRUE.
Needs a line break at the end of the file.
This probably also needs a test.
Comment #52
esolitosApplied suggested fixes from #51, missing still tests 'tho.
Comment #53
rackberg CreditAttribution: rackberg at comm-press commentedJust tried the solution posted in comment #43.
For me it works as expected. No need to create a patch.
Comment #54
rimen CreditAttribution: rimen commentedAnother solution is use hook_node_view_alter instead preproces to embed custom (extra) fields
All works as designed
Comment #55
loopduplicateThanks for the tip, @rimen . There's also hook_entity_view_alter() for other entity types.
Comment #56
loopduplicateComment #57
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commented