Default Images not rendered in layout builder

Created on 25 March 2024, 8 months ago
Updated 13 April 2024, 7 months ago

Problem/Motivation

Since Drupal 10.2.4 default images for users are not shown in blocks added by Layout Builder.
Image formatters are getting ignored too.
I am using a Module to replace the default image with a path based solution via image formatter so you can use config sync to sync default images. The module does not work anymore too because of the changes in 10.2.4.

Steps to reproduce

  • Set up a field storage default value for the user image
  • Switch view mode of user to use the layout builder and add the image as block

Proposed resolution

Check both image field storage and field settings for default image when checking FieldBlock access.

🐛 Bug report
Status

Fixed

Version

10.2

Component
Layout builder 

Last updated about 11 hours 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 @afoerster
  • Do you mean this worked in Drupal 10.2.3 and broke in 10.2.4 specifically? If "yes", is 🐛 Field block for empty image field with no default image rendering empty div in Layout Builder Fixed the reason?

  • Status changed to Postponed: needs info 8 months ago
  • 🇳🇿New Zealand danielveza Brisbane, AU

    Does the same issue exist if you follow the steps to replicate with just Drupal core?

    It may be an issue with the module you have linked rather than core itself.

  • I created the layout with 10.2.2, updated to 10.2.3 (still working) and after update to 10.2.4 it broke.
    The steps to reproduce contain the minimum steps to reproduce the problem, the mentioned module is not necessary.

    I tried to revert the changes introduced in #3398196 and it started working again.

  • The issue with contrib module Config default image appears to be separate from the issue with default image in core. The only relation being they were both surfaced by the fix in 🐛 Field block for empty image field with no default image rendering empty div in Layout Builder Fixed .

    Briefly about the contrib module: it allows users to set a default image path with the field formatter. Since the default value on the field item is detected to be empty (no uuid), the field formatter is never invoked. An issue for that module probably needs to be opened to address.

    Addressing the core issue here: Image field items can have a default image set at the storage level (so for all instances on the entity type) and at the bundle level. Using a standard 11.x install with Layout Builder, if I edit the User Picture field settings and set a default image on the field storage, then the image does not appear. However, if I set the default image on the instance (lower down on the form - see screenshot), then image does appear. My assumption is that when $field->getFieldDefinition()->getSetting('default_image')['uuid']) is called, at the very least, the default_image is not properly merged between the field storage setting and the field instance setting.

  • Pipeline finished with Failed
    8 months ago
    Total: 178s
    #130039
  • Pipeline finished with Failed
    8 months ago
    Total: 555s
    #130055
  • Pipeline finished with Success
    8 months ago
    Total: 668s
    #130064
  • Status changed to Needs review 8 months ago
  • Updated the default value detection for image fields to account for field storage settings. It's largely copied from Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase::getEntitiesToView(). Also updated tests.

  • Status changed to RTBC 8 months ago
  • 🇺🇸United States smustgrave

    Test-only feature does show the issue

    1) Drupal\Tests\layout_builder\Functional\LayoutBuilderDefaultValuesTest::testDefaultValues
    Behat\Mink\Exception\ResponseTextException: The text "field_image_storage_default" was not found anywhere in the text of the current page.
    /builds/issue/drupal-3435906/vendor/behat/mink/src/WebAssert.php:907
    /builds/issue/drupal-3435906/vendor/behat/mink/src/WebAssert.php:293
    /builds/issue/drupal-3435906/core/tests/Drupal/Tests/WebAssert.php:956
    /builds/issue/drupal-3435906/core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php:192
    /builds/issue/drupal-3435906/core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php:114
    /builds/issue/drupal-3435906/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    ERRORS!
    Tests: 1, Assertions: 7, Errors: 1.
    

    For my testing I used https://www.drupal.org/project/moderation_dashboard to get the layout builder for user display (too lazy to manually create). I added a new field image with a default. And placed within the dashboard. Belive I did see the issue and the patch does appear to address the issue.

    As this is a regression going to mark now so hopefully can be fixed in next release.

  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    The double default stuff is a mess, but this fix at least is consistent.

    Committed and pushed 3cf0c074d0 to 11.x and a365535543 to 10.3.x and 2839eeca7e to 10.2.x. Thanks!

    • alexpott committed 2839eeca on 10.2.x
      Issue #3435906 by godotislate, afoerster: Default Images not rendered in...
    • alexpott committed a3655355 on 10.3.x
      Issue #3435906 by godotislate, afoerster: Default Images not rendered in...
  • Status changed to Fixed 8 months ago
    • alexpott committed 3cf0c074 on 11.x
      Issue #3435906 by godotislate, afoerster: Default Images not rendered in...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024