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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

swentel’s picture

Project: Display Suite » Field Group
Version: 7.x-1.5 » 7.x-1.x-dev

Moving to field group

DuaelFr’s picture

I 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.

      $vars['test_preprocess_field'] = array (
        '#theme' => 'field',
        '#field_type' => 'ds',
        '#title' => 'Test preprocess field',
        '#label_display' => 'hidden',
        '#field_name' => 'test_preprocess_field',
        '#bundle' => 'avis_deces',
        '#items' => array (
          0 => array (
            'value' => 'Hi',
          ),
        ),
        0 => array (
          '#markup' => 'Hi',
        ),
      );

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 ?

DuaelFr’s picture

I 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

      $vars['content']['test_preprocess_field'][0] = array (
        '#markup' => 'Hi',
      );

and it take care of the weight defined in the arrange fields form.

I hope it can help.

DuaelFr’s picture

Project: Field Group » Display Suite
Status: Active » Needs review

Back in DS Issue list needing review :)

swentel’s picture

I can't seem to get this working at all. What exactly are you doing to get fieldgroups in there ?

swentel’s picture

Status: Needs review » Postponed (maintainer needs more info)
DuaelFr’s picture

Patch 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.

DuaelFr’s picture

I 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.

DuaelFr’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
426 bytes

This time is the good one !
(Sorry)

swentel’s picture

Status: Needs review » Needs work

No 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.

DuaelFr’s picture

I 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 :/

swentel’s picture

Status: Needs work » Closed (won't fix)

You 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.

DuaelFr’s picture

The 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 ;)

danielbeeke’s picture

I 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

danielbeeke’s picture

Ah excuses, I see that I left a approach in it that I tried.

danielbeeke’s picture

Status: Closed (won't fix) » Needs review

status

dooug’s picture

I 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.

+++ b/ds.module
@@ -636,7 +642,7 @@ function ds_field_attach_view_alter(&$build, $context) {
+    if (!empty($field_value) || (string) $field_value === '0' || $field['field_type'] == DS_FIELD_TYPE_PREPROCESS && $field['module'] == 'ds') {

@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.

danielbeeke’s picture

aspilicious’s picture

Issue summary: View changes
Status: Needs review » Closed (won't fix)

Won'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.

sonictruth’s picture

Status: Closed (won't fix) » Needs review

Exotic 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:

Warning: Invalid argument supplied for foreach() in element_children() (line 6542 of site/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5999 of site/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 6009 of site/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 6047 of site/includes/common.inc).
Warning: Illegal string offset '#printed' in drupal_render() (line 6054 of site/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6542 of site/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5999 of site/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 6009 of site/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 6047 of site/includes/common.inc).
Warning: Illegal string offset '#printed' in drupal_render() (line 6054 of site/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6542 of site/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5999 of site/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 6009 of site/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 6047 of site/includes/common.inc).
Warning: Illegal string offset '#printed' in drupal_render() (line 6054 of site/includes/common.inc).

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().

sonictruth’s picture

Looks 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.

aspilicious’s picture

The 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.

Dom.’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
FileSize
2.81 KB

Repacked 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 ?)

hpz’s picture

Thanks, Dom for this patch.
I applied it today and it works fine!

8bitplateau’s picture

Manually 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.

8bitplateau’s picture

Spoke 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 ?