diff --git a/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php b/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php index 578f9348eb72c8d4e2b1f5b954f75e8e552732a3..b3998899cab5241471cbbdd6d9eacbd5fefc044f 100644 --- a/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php +++ b/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php @@ -215,7 +215,7 @@ protected function blockAccess(AccountInterface $account) { if ($field->isEmpty() && !$field->getFieldDefinition()->getDefaultValue($entity)) { // @todo Remove special handling of image fields after // https://www.drupal.org/project/drupal/issues/3005528. - if ($field->getFieldDefinition()->getType() === 'image' && $field->getFieldDefinition()->getSetting('default_image')) { + if ($field->getFieldDefinition()->getType() === 'image' && !empty($field->getFieldDefinition()->getSetting('default_image')['uuid'])) { return $access; } diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php index b95ed63e87d705aca23cf6d2b651d569dd2ae210..b65672672391243629021cd5d42797531f3d9bdb 100644 --- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderDefaultValuesTest.php @@ -15,6 +15,8 @@ use Drupal\Tests\image\Kernel\ImageFieldCreationTrait; use Drupal\Tests\TestFileCreationTrait; +// cspell:ignore blocknodetest typefield + /** * Tests rendering default field values in Layout Builder. * @@ -141,6 +143,15 @@ protected function assertNodeWithValues() { * Test for expected text on node 2. */ protected function assertNodeWithDefaultValues() { + // Switch theme to starterkit_theme so that layout builder components will + // have block classes. + /** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */ + $theme_installer = $this->container->get('theme_installer'); + $theme_installer->install(['starterkit_theme']); + $this->config('system.theme') + ->set('default', 'starterkit_theme') + ->save(); + $this->drupalGet('node/2'); $assert_session = $this->assertSession(); // String field with no default should not render. @@ -160,6 +171,9 @@ protected function assertNodeWithDefaultValues() { $assert_session->responseContains('test-file-1'); // Image field with no default should not render. $assert_session->pageTextNotContains('field_image_no_default'); + // Confirm that there is no DOM element for the field_image_with_no_default + // field block. + $assert_session->elementNotExists('css', '.block-field-blocknodetest-node-typefield-image-no-default'); } /**