I have a content type with several fields including paragraph fields. I have a sidebar region and have created a simple view which creates a block and displays the current node and for the format I have selected rendered entity and for the display mode I have selected "sidebar first" which is one of the display modes I have enabled for this content type.

On manage display for "sidebar first" I have two fields, an entity reference field and a paragraphs field. On both I have enabled display suite and field templates and have chosen the "expert" field template in order to change the markup / class for the label and output everything else clean.

The entity reference field is outputting as expected but the expert field template is being ignored on the paragraphs field and it being output using the Drupal default.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vaccinemedia created an issue. See original summary.

Pryrios’s picture

I think I may have found the issue regarding this.

On Display Suite Extras, when doing the preprocess on ds_extras_preprocess_field the host entity is checked to see if there is a DS layout, otherwise DS extras cannot be applied. Parameters are the entity type of the host entity, bundle and view mode. The view mode passed onto that check is the one on the element array, along with the entity type and bundle also present on that element.

When configuring the formatter for a paragraph field on Manage Display, a view mode is selected. Then on paragraphs_field_formatter_view when building the $element variable, the view mode assigned is the one from the configuration, but I think this is wrong. It should assign the view mode of the parent entity.

Clarification: This happens to me on a multivalue Paragraph field. I have not tested a single value field.

Pryrios’s picture

Proposed fix. This should keep the classes on paragraphs fields while not breaking the DS theming of extras. I don't think the #view_mode is being used anywhere else outside the preprocess so this should be safe.

Pryrios’s picture

Status: Active » Needs work
hanoii’s picture

Very interesting this is almost the same patch as a 3 years old issue #2638780: Conflict with Field API #view_mode. See the maintainer response there. I am trying to figure if there's secondary issue or not.

I was also tracking odd issues with view modes, can you maybe also try #3066229: View mode on the paragraph field is not respected if you can.

hanoii’s picture

Status: Needs work » Reviewed & tested by the community

From #2638780-4: Conflict with Field API #view_mode:

Also. What's the exact issue here? When I breakpoint at that point $view_mode is 'full' for me. The view mode of the node I'm looking at.

After some testing I see what you are talking about when using nested paragraphs, but I'm not sure this is a problem in Paragraphs, it does not seem to make sense to pass the view mode of the top entity being viewed as #view_mode...

I tried reviewing this, and I think it just works properly with and without nested entities, and found no issues.

Why "needs work" @Pryrios?

Pryrios’s picture

First of all it probably needs automated tests to verify it is working properly.

Then, the fix is very simple, so I may be breaking something, but seeing that it passed current tests, maybe not.

I will gladly write tests for this patch, but I am not very fluent at writing them so it may take me a while. If anyone wants to take a stab at it meanwhile, it is welcome.

  • jstoller committed e1edfc5 on 7.x-1.x authored by Pryrios
    Issue #3044164 by Pryrios, hanoii: Display suite field templates ignored...
jstoller’s picture

Status: Reviewed & tested by the community » Fixed

Patch committed to dev.

Status: Fixed » Closed (fixed)

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