Steps to reproduce:

  1. Go to /admin/structure/types/manage/article/display.
    Configure a ds layout with fields for 'default' view mode.
  2. Go to /admin/structure/types/manage/article/display/teaser.
    Choose a ds layout, and put one of the fields into the content region.
  3. Go to /devel/php, and execute dpm(ds_get_field_settings('node', 'article', 'teaser'));.
    Result: The fields configured for 'teaser' view mode show up.
  4. Go again to /admin/structure/types/manage/article/display/teaser.
    Remove all fields from all regions.
  5. Go to /devel/php, execute dpm(ds_get_field_settings('node', 'article', 'teaser'));.
    Expected result: Empty array.
    Actual result: The fields configured for 'default' view mode.

Use case:
In my case, a custom ds layout that does some magic by itself, and does not need any fields.
As a more general case: A ds layout that is filled with some fields, but none of them is a "ds field".

Problem:
Some fields are processed even though they are disabled.
In my case, one of them - a "related products" view - caused an infinite loop.

Technical explanation:
ds_field_ui_fields_save() deletes the old entry in the ds_field_settings table, and only creates a new entry if the fields are not empty.
ds_get_field_settings() falls back to the 'default' view mode, if it does not find an entry in the ds_field_settings table.
ds_field_attach_view_alter() calls ds_get_field_settings($entity_type, $bundle, $view_mode), and then processes all the fields.

Possible solutions

In ds_field_ui_fields_save(), save an entry with empty array in the ds_field_settings table, if no fields are enabled.

or

In ds_get_field_settings(), do NOT fall back to 'default' if there are layout settings for this view mode.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

donquixote created an issue. See original summary.

donquixote’s picture

donquixote’s picture

Sorry, I had forgotten the older issue, #2216661: infinite recursion with extra fields.
Still, I think this new issue has a more focused title description.

donquixote’s picture

Issue summary: View changes
donquixote’s picture

Status: Active » Needs review
FileSize
718 bytes
donquixote’s picture

Issue summary: View changes
donquixote’s picture

Here is an alternative solution.

From #2216661: infinite recursion with extra fields

This changes the behaviour to NOT perform a fallback... That's like a big change, this probably will break a lot of things.

What would be a case where the fallback is intended and legitimate?

It does make sense if the entire view mode has no dedicated configuration, and uses the default configuration instead.
In this case, ds_get_layout() will already return the default layout.
And then, ds_get_field_settings($entity_type, $bundle, $layout['view_mode']) will already get the field settings for the default layout.
But, if ds_get_layout() returns a dedicated layout for the given view mode, we also need the dedicated field settings, even if this is empty.