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.
Hi !
I am trying to use DS to set up my display more consistently than just by hacking some templates.
I need to make a simple div field group containing three preprocess fields.
Dynamic, code and block fields seems to work well but any of my preprocess field want to stay into the group...
I join you a screenshot showing the problem.
Feel free to ask if you need more information.
Regards.
Comment | File | Size | Author |
---|---|---|---|
#23 | sd_preprocess_field_inside_fieldgroup--1452198-23.patch | 2.81 KB | Dom. |
#15 | ds-preprocess-fieldgroup-compatability-2.patch | 2.78 KB | danielbeeke |
#14 | ds-preprocess-fieldgroup-compatability.patch | 3.25 KB | danielbeeke |
#9 | 1452198-9-add-options-preprocess.patch | 426 bytes | DuaelFr |
#8 | 1452198-8-add-options-preprocess.patch | 510 bytes | DuaelFr |
Comments
Comment #1
swentel CreditAttribution: swentel commentedMoving to field group
Comment #2
DuaelFrI finally got it running.
I was using the only blog post I found to know how preprocess fields are working but it seems to be incomplete !
Digging a lot I ended with this minimal piece of code to get it work with fieldgroups.
The problem is that I did not find how to dynamically set the field weight using the "arrange display" form...
I really think that preprocess fields may come with all this basic stuff and let developpers/themers deal with the content.
Did I miss something important ?
Comment #3
DuaelFrI made a tiny fix to DS 7.x-1.x-dev for the preprocess fields to presetted with a proper options array.
With this, the custom preprocess content definition code is restricted to something like
and it take care of the weight defined in the arrange fields form.
I hope it can help.
Comment #4
DuaelFrBack in DS Issue list needing review :)
Comment #5
swentel CreditAttribution: swentel commentedI can't seem to get this working at all. What exactly are you doing to get fieldgroups in there ?
Comment #6
swentel CreditAttribution: swentel commentedComment #7
DuaelFrPatch is running very well on my environment.
Fieldgroups seems to ignore fields that do not implement all the basic stuff that fields must carry (see #2).
My patch prefill preprocess fields array with things drupal and fieldgroups are looking for.
I thought that #2 and #3 were self-explanatory.
Comment #8
DuaelFrI have just seen the new dev version.
Here is my rerolled patch.
EDIT : Take the #9 file... The paths are not correct in this one.
Comment #9
DuaelFrThis time is the good one !
(Sorry)
Comment #10
swentel CreditAttribution: swentel commentedNo luck again :)
What I'm doing is this:
- create a preprocess field through the UI. The key is 'submitted' (so that it prints the 'Submitted by ...)
- create field group (tested with both branches)
- move that into the fieldgroup
- apply the patch, but the submitted line is not in the fieldgroup.
So no, this patch doesn't work at all with preprocess fields that display suite can provide out of the box.
Comment #11
DuaelFrI think you have to put something in your preprocess field...
These fields are empty boxes so you have to write a preprocess function to fill them with content. If not, field is not rendered nor fieldgroup.
If you follow the article here (http://www.lullabot.com/articles/display-suite-building-fancy-teasers-wi...) you will be able to fill it then you wil see it is not in the fieldgroup but out.
I think you may try with a totally new key like 'my_preprocess_field' which is not overriden by any Drupal functions.
My purpose is to create fields which content can depend on other fields. I could use a code field with the php code module but I think this is a real plague for professionnal developpers. Seeing PHP code in a textarea make me suffer a lot :/
Comment #12
swentel CreditAttribution: swentel commentedYou can also define your own custom field in a module with the hook_ds_fields_info() hook, see http://drupalcode.org/project/ds.git/blob/refs/heads/7.x-1.x:/ds.api.php.... That's how we usually expose new content through fields, which are build nicely and will get into fieldgroups. We don't use the code field much either :) I guess that adding support for preprocess fields maybe wasn't the best option, but there're other ways to expose content in a module very easily and nice :)
I'm going to won't fix this for now. I'll try to have a new look maybe next week to see if I can maybe fix this in the second branch, but I doubt it.
Comment #13
DuaelFrThe fact is that preprocess fields are not presetted by the code line 751 of ds.module because, as their name says, they are empty until preprocess functions fill them.
If the developper wants to, he can build the array himself but it will not take care of field's selected weight or label display for example.
Thank you for the documentation (500 error for now...) I will have a closer look at this for my future projects. I think I will write some documentation after that because it is not really self-explanatory ;)
Comment #14
danielbeeke CreditAttribution: danielbeeke commentedI have created a fix for this issue.
I really like the simple way of preprocessing a node and adding a preprocess field via display suite.
I would like to hear if my approach is good.
Daniel
Comment #15
danielbeeke CreditAttribution: danielbeeke commentedAh excuses, I see that I left a approach in it that I tried.
Comment #16
danielbeeke CreditAttribution: danielbeeke commentedstatus
Comment #17
dooug CreditAttribution: dooug commentedI have a site set up with many preprocess fields. Now I am trying to add them to a group and spent too long figuring out this issue.
I tried the patch in #15 but it didn't work. I reviewed it a bit, and realized it would only work if the module defining the preprocess field was ds.
So, I had to remove the last condition,
&& $field['module'] == 'ds'
, in the following line.@danielbeeke, why was that included in that conditional?
With that, my preprocess fields do finally show up in the appropriate field group. Although, I haven't thoroughly reviewed how the patch does this.
Comment #18
danielbeeke CreditAttribution: danielbeeke commentedIts some time ago.
Nowadays I use hook_field_extra_fields
https://api.drupal.org/api/drupal/modules!field!field.api.php/function/h...
http://www.computerminds.co.uk/drupal-code/add-stuff-node-and-configure-...
Comment #19
aspilicious CreditAttribution: aspilicious commentedWon't fix this for drupal 7. Time to ignore these exotic use cases and point to valid alternatives. And there are many pointed out in this issue.
Preprocess fields will be gone in Drupal8.
Comment #20
sonictruth CreditAttribution: sonictruth at Kalamuna commentedExotic use cases? I would have thought a preprocess field inside a field group would be a fairly vanilla use case. Patch from #15 got the field inside the group but it's throwing a lot of other errors now:
There's another much more recent issue for the same problem over here: https://www.drupal.org/node/1342878 but none of the patches there fixed anything for me.
Not sure if I'm going to have time to track down and fix the above errors so might have to just throw in the towel and try hook_ds_fields_info() or hook_field_extra_fields().
Comment #21
sonictruth CreditAttribution: sonictruth at Kalamuna commentedLooks like those errors were from something unrelated. The patch from #15 works for me and really should be rolled in. Without it, one of the solid use cases for DS is broken, regardless of what is coming up in D8.
Comment #22
aspilicious CreditAttribution: aspilicious commentedThe point is that using preprocess fields are a can of worms, a lot of issues in the issue queue are caused by them.
There are better alternatives like creating custom ds field functions, that don't have these issues and are less buggy in general.
https://www.previousnext.com.au/blog/creating-custom-display-suite-field...
I don't want to add *more* workaround code. I just want to force people in using the tools in stable and maintainable way.
Comment #23
Dom. CreditAttribution: Dom. as a volunteer commentedRepacked patch #15 with the following changes:
- update patch to apply on branch 7.x-2.x
- update patch to remove the 'ds' module field condition (see #17 by @dooug)
- remove one arguments that did not match the fieldgroup reorder function call (maybe reason of #18 ?)
Comment #24
hpz CreditAttribution: hpz commentedThanks, Dom for this patch.
I applied it today and it works fine!
Comment #25
8bitplateau CreditAttribution: 8bitplateau commentedManually applied the patch to 7.x-2.x-dev, it works.
Now Display Suite's (DS Extra's) Preprocess Fields work with Field Group properly and respect their order.
Comment #26
8bitplateau CreditAttribution: 8bitplateau commentedSpoke to soon - the patch seems to break Display Suite Extras' Views Displays.
With patch applied - all views using layouts return empty sections (pager, content, header etc), removing the patch makes them appear again and Views Displays work as expected.
Can anyone else confirm this ?