Hey and thank you very much for this great module. Sadly we were running into an edge-case which lead to several hours bug searching...

Context:

Using semantic_fields in a custom view mode vs. default display.

Problem:

After disabling the custom view mode and using the default view mode again the semantic_fields settings from the custom view mode still apply (incorrectly!) and lead to confusion.

Solution:

Use field_view_mode_settings(); to check if the selected view mode is active, otherwise fall back to default!
See patch in #1.

Comments

Anybody created an issue. See original summary.

anybody’s picture

Patch attached. We've tested it for our projects and it works great, solving the problems.

anybody’s picture

Status: Active » Needs review
andileco’s picture

Status: Needs review » Needs work

Hey @Anybody, I had to adjust to this to prevent the notices:

// Determine if the view mode is active and has custom settings:
  $view_mode_settings = field_view_mode_settings($element['#entity_type'], $element['#bundle']);
  $view_mode_has_custom_settings = (!empty($element['#view_mode']) && !empty($view_mode_settings[$element['#view_mode']]['custom_settings']));
  $display = ((!empty($element['#view_mode']) && !empty($instance['display'][$element['#view_mode']]) && $view_mode_has_custom_settings) ? (!empty($element['#view_mode']) && $instance['display'][$element['#view_mode']]) : $instance['display']['default']);

(mostly just checking that $element['#view_mode'] was not null). I haven't tried to write this more efficiently, so marked it as "Needs work"

anybody’s picture

Hey @andileco, which kind of notices did you get? Could you create a patch?