Skip to content
Snippets Groups Projects
Commit 63eddaef 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
parent 74851391
No related branches found
No related tags found
No related merge requests found
...@@ -215,7 +215,7 @@ protected function blockAccess(AccountInterface $account) { ...@@ -215,7 +215,7 @@ protected function blockAccess(AccountInterface $account) {
if ($field->isEmpty() && !$field->getFieldDefinition()->getDefaultValue($entity)) { if ($field->isEmpty() && !$field->getFieldDefinition()->getDefaultValue($entity)) {
// @todo Remove special handling of image fields after // @todo Remove special handling of image fields after
// https://www.drupal.org/project/drupal/issues/3005528. // 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; return $access;
} }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
use Drupal\Tests\image\Kernel\ImageFieldCreationTrait; use Drupal\Tests\image\Kernel\ImageFieldCreationTrait;
use Drupal\Tests\TestFileCreationTrait; use Drupal\Tests\TestFileCreationTrait;
// cspell:ignore blocknodetest typefield
/** /**
* Tests rendering default field values in Layout Builder. * Tests rendering default field values in Layout Builder.
* *
...@@ -141,6 +143,15 @@ protected function assertNodeWithValues() { ...@@ -141,6 +143,15 @@ protected function assertNodeWithValues() {
* Test for expected text on node 2. * Test for expected text on node 2.
*/ */
protected function assertNodeWithDefaultValues() { 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'); $this->drupalGet('node/2');
$assert_session = $this->assertSession(); $assert_session = $this->assertSession();
// String field with no default should not render. // String field with no default should not render.
...@@ -160,6 +171,9 @@ protected function assertNodeWithDefaultValues() { ...@@ -160,6 +171,9 @@ protected function assertNodeWithDefaultValues() {
$assert_session->responseContains('test-file-1'); $assert_session->responseContains('test-file-1');
// Image field with no default should not render. // Image field with no default should not render.
$assert_session->pageTextNotContains('field_image_no_default'); $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');
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment