diff --git a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php index 21eeb06..ca40a5b 100644 --- a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php +++ b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php @@ -140,7 +140,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen if (empty($default_image['fid'])) { $default_image = $this->fieldDefinition->getFieldStorageDefinition()->getSetting('default_image'); } - $element['#default_image'] = $default_image; + $element['#default_image'] = !empty($default_image['fid']) ? $default_image : array(); return $element; } diff --git a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php index 38fc142..c5f10ae 100644 --- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php @@ -245,6 +245,11 @@ public function testDefaultImages() { ) ); + // Confirm the preview image is shown on the node/add/article. + $file = entity_load('file', $default_images['instance_new']->id()); + $this->drupalGet('node/add/article'); + $this->assertRaw($file->getFilename()); + // Remove the instance default from articles. $instance->settings['default_image']['fid'] = 0; $instance->save(); @@ -282,6 +287,11 @@ public function testDefaultImages() { $non_image = $this->drupalGetTestFiles('text'); $this->drupalPostForm(NULL, array('files[instance_settings_default_image_fid]' => drupal_realpath($non_image[0]->uri)), t("Upload")); $this->assertText(t('The specified file text-0.txt could not be uploaded. Only files with the following extensions are allowed: png gif jpg jpeg.'), 'Non-image file cannot be used as default image.'); + + // Confirm the preview image is shown on the node/add/article. + $file = entity_load('file', $default_images['field_new']->id()); + $this->drupalGet('node/add/article'); + $this->assertRaw($file->getFilename()); } /**