Commit 9540258e authored by catch's avatar catch
Browse files

Issue #3398196 by godotislate, DanielVeza, smustgrave: Field block for empty...

Issue #3398196 by godotislate, DanielVeza, smustgrave: Field block for empty image field with no default image rendering empty div in Layout Builder

(cherry picked from commit 63eddaef)
parent 0baa35af
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;
      }

+14 −0
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@
use Drupal\Tests\image\Kernel\ImageFieldCreationTrait;
use Drupal\Tests\TestFileCreationTrait;

// cspell:ignore blocknodetest typefield

/**
 * Tests rendering default field values in Layout Builder.
 *
@@ -139,6 +141,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.
@@ -158,6 +169,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');
  }

  /**