Doesn't work in layout builder

Created on 8 December 2019, over 5 years ago
Updated 6 February 2025, 5 months ago

If you place a field using Layout Builder and try to give it a delimiter, your setting is ignored. This is related to #3061187: #view_mode is always "_custom" in HOOK_preprocess_field() with layout_builder enabled β†’ .

A fix here looks like this:

  $view_mode = $element['#view_mode'];

  // Add a check for Layout Builder alternative settings.
  if ($view_mode == '_custom') {
    $view_mode = $element['#third_party_settings']['layout_builder']['view_mode'];
  }

Note that this fix will only work in Drupal 8.8+, in earlier versions it's just broken.

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States KarenS

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies

    Is this relevant for 2.x as well?

  • πŸ‡ͺπŸ‡ΈSpain pcambra Asturies
  • πŸ‡¦πŸ‡ΊAustralia dabbor

    The fix (patch) in comment #4 seems to be the right approach (3099580-layout-builder-view-mode.patch), but it does not work with 2.0.x (2.0.x-dev) version.

    I re-applied the patch for 2.0.x, the following line of the #4 patch had to bechanged:
    - FROM: $view_mode = $element['#third_party_settings']['layout_builder']['view_mode'];
    - TO: $view_mode = $variables['element']['#third_party_settings']['layout_builder']['view_mode'];

Production build 0.71.5 2024