In my content type I have block, code and preprocess fields along with normal fields displayed in Fluid two column stacked template.

When I edit the fields in manage display tab and sort them the order of fields is stored fine. However when I view the content the order of fields is not the same as set in manage display tab. One of fields is displayed two fields "higher" than it should be. When I rearrange the fields a little then other field is displayed higher than it sould be. This is happening only in the middle of one region.

I've recently updated Drupal to 7.22 and Display Suite version is 7.x-2.4. Could you help me and suggest what can I try to debug in preprocess function or somewhere else to check what's changing my fields order?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

philipz’s picture

OK, I've switched to show fields' weights and entered weights for fields around the place where problem occured like that: 1,2,3,4,15,16,17.
Now the fields display as they should.
The weights before I changed them manually were: 8,9,10,11,12,13,14 so that should not have been the problem.

oeroek’s picture

I have the same problem. I use Drupal 7.22 and DS 7.x-2.4. I added preprocess fields using the technique in http://www.lullabot.com/blog/display-suite-building-fancy-teasers-withou...

I also use Fieldgroup 7.x-1.1 to make some horizontal tabs and div groups. The horizontal tabs are fine. The preprocessed fields above the tabs are looking fine when working in the admin view "manage displays". When I open the page itself, some preprocessed fields that drop from above the horizontal tabs group to the bottom.

Solution in comment # worked for me. Not sure if the problem is in Fieldgroup or in DS. it seems however that the drag and drop numbering of preprocessed fields is not correct.

Edit: when working further on this I noticed that the problems seem to concentrate to preprocess fields in combination with fieldgroup to make horizontal tabs. I changed the preprocess blocks into code fields and that also solves the problem for me.

Diane Bryan’s picture

Same problem today with Drupal 7.23 and Display Suite 7.x-2.5, sorry to say. I was able to trick DS into eventually putting things where I want them by continuing to rearrange them until they were right.

SchnWalter’s picture

Assigned: Unassigned » SchnWalter
Status: Active » Needs review
FileSize
4.49 KB
2.59 KB

When attaching the preprocess field to the $variables['content'] array an weight should be specified, this is the root of the problem.

The attached diff file contains the minimum required changes to v7.x-2.6 in order to fix this issue. And the patch contains an attempt to clarify the code.

aspilicious’s picture

  1. +++ b/ds.module
    @@ -426,13 +426,13 @@ function ds_get_field_value($key, $field, $entity, $entity_type, $bundle, $view_
    -    $entity->preprocess_fields[] = $key;
    +    $entity->preprocess_fields[$key] = $field['weight'];
       }
     
       switch ($field['field_type']) {
     
         case DS_FIELD_TYPE_PREPROCESS:
    -      $entity->preprocess_fields[] = $key;
    +      $entity->preprocess_fields[$key] = $field['weight'];
    

    It sounds weird to have $weight as a value. Is it possible to swap these around?

  2. +++ b/ds.module
    @@ -511,35 +511,36 @@ function ds_field_attach_view_alter(&$build, $context) {
    -    $field = $fields[$key];
    -    if (isset($field_values[$key]['format'])) {
    -      $field['formatter'] = $field_values[$key]['format'];
    -    }
    +    // Merge field definition with the instance settings.
    +    $field = array_merge($ds_fields[$key], $instance_settings);
    

    Can you explain why the merge is necesary?

  3. +++ b/ds.module
    @@ -511,35 +511,36 @@ function ds_field_attach_view_alter(&$build, $context) {
    -    if (isset($field_values[$key]['formatter_settings'])) {
    -      $field['formatter_settings'] = $field_values[$key]['formatter_settings'];
    +    if (isset($field['format'])) {
    +      $field['formatter'] = $field['format'];
    

    This changes formatter_settings to formatter. Is this a bug or why are you doing this?

  4. +++ b/ds.module
    @@ -550,8 +551,8 @@ function ds_field_attach_view_alter(&$build, $context) {
    -          '#weight' => isset($field_values[$key]['weight']) ? $field_values[$key]['weight'] : 0,
    -          '#label_display' => isset($field_values[$key]['label']) ? $field_values[$key]['label'] : 'inline',
    +          '#weight' => isset($field['weight']) ? $field['weight'] : 0,
    +          '#label_display' => isset($field['label']) ? $field['label'] : 'inline',
    

    Note to self, I have to verify if this is actually the same

SchnWalter’s picture

1. Agree, it sounds wierd.

2. The $field variable used to contain only the field base settings: "$field = $fields[$key];" and we need the field weight in there which is in the instance_settings. Maybe we can have the 'instance_settings' inside
the $field array instead of having them merged.

3. It was already in there, not sure where it comes from. I would remove it, but i'm not sure if it's still used somewhere.

4. They are the same if we merge the arrays from 2.

ohthehugemanatee’s picture

Issue summary: View changes

Noting that I encountered this problem, and this patch fixed it for me. I'm not a helpful case study though because I have fieldgroups, field collections, and custom (DS) fields... so any one of those complications could be the culprit.

In any case, it looks like it's working with the patch.

bleen’s picture

FWIW I'm having a similar problem, but the patch in #4 did not help

ohthehugemanatee’s picture

after a few more months, it was a false positive. We've had to re-do field order a few times since then. :|

Anonymous’s picture

I've run into this just now, in a simple case. I created a display for book pages. The book navigation (pseudo-)field and links (pseudo-)field ended up in random order. Repeated manual bashing of the row weights non-deterministically changed the ordering. There were no non-built-in fields involved, or other modules that seem likely to have interfered.

So: It's definitely broken.

I haven't tried the patch, based on the negative reports here.

Anonymous’s picture

Status: Needs review » Needs work

Changing status based on failure reports above, and the concerns of aspilicious.

monaw’s picture

I just updated to DS 2.7 and the problem is still there for me ):

haunted’s picture

I have the same problem but for a code field.
I'm using ds 7.x-2.7

loopduplicate’s picture

Not sure if this will help anyone but figured I'd share. I did this to update the ordering for a site I'm working on:

/**
 * Implements hook_ds_pre_render_alter().
 * 
 * Orders the display of Display Suite fields for the Example Content Type. Without this
 * implementation, some fields may render out of order.
 */
function example_ds_pre_render_alter(&$layout_render_array, &$context, &$variables) {
  if (!empty($context['bundle']) && $context['bundle'] === 'example_content_type') {
    foreach($layout_render_array as $region => &$fields) {
      foreach ($fields as $field_key => &$field) {
        $field['#weight'] = $field_key;
      }
    }
  }
}

loopduplicate’s picture

I should mention that in my case, the field that was rendering out of order was a preprocess field. The preprocess field kept appearing after a block reference field (from the Block Reference module.)

Erik Seifert’s picture

#14 Thanks help for a workaround.

heddn’s picture

This fixes it for me. Credit goes to @loopduplicate for the suggestion in #14. I'm pretty sure this should be tested by more than just me. But it definitely works for pre-render field types.

heddn’s picture

Status: Needs work » Needs review
pandaski’s picture

Version: 7.x-2.4 » 7.x-2.10

#17 is a solution working for me

I am using 7.x-2.10, and this fixes block field out of order issue as well

Plazik’s picture

Version: 7.x-2.10 » 7.x-2.x-dev
Status: Needs review » Reviewed & tested by the community

Path from #17 works for me too.

sonictruth’s picture

Patch from #17 works for me

aspilicious’s picture

Assigned: SchnWalter » bceyssens

This is such a patch that looks harmless but could explode in my face once I create a new release.
I would like to have some more testing before I commit this.

Assigning to Brecht for additional testing.

aspilicious’s picture

Can someone share a scenario were the order is incorrect?

StG’s picture

#17 worked for me, thanks.

Here's my scenario:
I created 4 preprocess fields and moved them to the top of the display. Below them there are several field collections. 3 preprocess fields are shown in the right place but the last one was moved down, between two field collections.

aspilicious’s picture

Status: Reviewed & tested by the community » Fixed

I don't like preprocess fields...
Luckily this is different for D8.

Committed this. will tag a new release next week if the dev version works for everyone.

  • aspilicious committed 1b0fef2 on 7.x-2.x authored by heddn
    Issue #2035531 by SchnWalter, heddn: Display order/weight of fields...

Status: Fixed » Closed (fixed)

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