Layout Builder shouldn't use the default value to determine whether a field has a value or not

Created on 10 June 2024, 11 months ago

Problem/Motivation

This workaround was initially introduced in #3119786: Default values are not displayed for image fields placed in Layout Builder and added specifically for the image field type.

The default value specified in the field type is typically only used for new entities created within the form display, and not the view display, since it simply provides a default value (which can be deleted if the field is not required).

The image field type is one of the few exceptions which attempts to populate and render a field value even if it actually flags itself as empty.

Attempting to support this image-specific edge case has caused a knock-on effect affecting other fields, and as long as they have a default value specified, then a label will always be attached regardless of if the underlying field is empty which shouldn't be the case.

Steps to reproduce

  1. Add a simple field with a default field value to a content type.
  2. Create a piece of content with that field empty.
  3. Add that field block in Layout Builder, and it'll show the field label on the front-end

Proposed resolution

Following options are available:

Remaining tasks

Discussion/PR.

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Layout builder 

Last updated 1 day ago

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @codebymikey
  • Pipeline finished with Failed
    11 months ago
    Total: 665s
    #195643
  • Status changed to Postponed: needs info 11 months ago
  • 🇳🇿New Zealand danielveza Brisbane, AU

    Hello! Thank you for raising a very detailed issue.

    Could you please confirm that the steps to reproduce in the IS are with a fresh install of Drupal 11? If not can they be updated with the steps to reproduce starting with a fresh install of D11?

    I'm asking because I've tried to this and I've been unable to replicate this. The steps I've followed are below:

    • Fresh install of a standard D11 site
    • Enabled LB
    • Added Layout builder to articles
    • Added a text field to articles with a default value of "Default text"
    • Created a new article and removed the default value from the field
    • Went to LB for the article and added the fieldblock for the new field.
    • I'm not able to see the label as described in the IS

    Thanks!

  • Yes, this is replicable on a clean installation using Simplytest. And sorry I mispoke, the behaviour more apparent when the "Display title" option is ticked on the block.

    Relevant links available here (username: admin, password: admin):

  • Status changed to Needs work 11 months ago
  • First commit to issue fork.
  • Pipeline finished with Failed
    11 days ago
    Total: 640s
    #483502
  • Pipeline finished with Failed
    11 days ago
    Total: 536s
    #483510
  • Pipeline finished with Failed
    11 days ago
    Total: 522s
    #483520
  • Pipeline finished with Failed
    11 days ago
    Total: 688s
    #483524
  • Pipeline finished with Success
    11 days ago
    Total: 668s
    #483528
  • 🇮🇳India nmudgal

    Updated the patch to fix all related test failures:

    • LayoutBuilderDefaultValuesTest: Adjusted alt text and file name checks to correctly match fields with storage/instance defaults. Updated string field checks for default value handling.
    • FieldBlockTest: Fixed access check logic when a field is empty but has a default value. Access should be allowed in that case.
    • BlockFilterTest: Adjusted block filter assertions to handle variations in block counts when filtering by text like "ad" or "adm".
  • 🇺🇸United States smustgrave

    Seems more like a feature request and disruptive one for existing sites

Production build 0.71.5 2024