drupal_field not working with Layout Builder enabled

Created on 12 September 2023, 10 months ago
Updated 20 January 2024, 5 months ago

Problem/Motivation

Drupal Core version: 10.1.3
Twig Tweak: 3.2

I want to render a field from a content type which uses Layout Builder for the view mode "full/default".

But the field is not rendered by using:

{{ drupal_field('field_name', 'node', entityId, 'full') }}

On the other hand I have configured, for the same content type, the view mode "teaser" without layout builder

And this time it works properly using:
{{ drupal_field('field_name', 'node', entityId, 'teaser') }}

The output of twig dump for the two cases shows that for the view mode "full", the object to render has been removed, whereas in the second case it remains.

Steps to reproduce

1. Create a content type with some fields
2. Configure the view mode "default" tom use layout builder

3. Configure another view mode (i,e: teaser) to not use layout builder

4. In the corresponding twig template try:

{{ drupal_field('field_name', 'node', entityId, 'full') }} <= Field is not rendered 
{{ drupal_field('field_name', 'node', entityId, 'teaser' }} <= Field is rendered 

After some investigation I discovered the piece of code responsible for deleting the object from render array:
In the file "LayoutBuilderEntityViewDisplay.php" Line 282 we can see:

After this foreach, the field is not present anymore.

I don't know if this problem should and can be solved in this module or it's maybe a problem on Layout Builder side.

Proposed resolution

If it's not possible to solve this problem because it probably depends on Layout Builder, it would be nice to have a kind of notice in the documentation, so that one can configure a view mode specifically for that case.

πŸ› Bug report
Status

Fixed

Version

3.2

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany juagarc4

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024