Loading core/modules/image/src/Plugin/Field/FieldType/ImageItem.php +1 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ public static function defaultStorageSettings() { 'width' => NULL, 'height' => NULL, ], 'display_default' => TRUE, ] + parent::defaultStorageSettings(); } Loading core/modules/image/tests/src/Kernel/ImageItemTest.php +28 −1 Original line number Diff line number Diff line Loading @@ -5,14 +5,20 @@ namespace Drupal\Tests\image\Kernel; use Drupal\Core\Database\Database; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormState; use Drupal\entity_test\Entity\EntityTest; use Drupal\field\Entity\FieldConfig; use Drupal\Tests\field\Kernel\FieldKernelTestBase; use Drupal\field\Entity\FieldStorageConfig; use Drupal\file\Entity\File; use Drupal\Tests\field\Kernel\FieldKernelTestBase; use Drupal\user\Entity\Role; /** Loading Loading @@ -92,6 +98,9 @@ protected function setUp(): void { ]); $this->image->save(); $this->imageFactory = $this->container->get('image.factory'); $this->container->get(EntityDisplayRepositoryInterface::class) ->getFormDisplay('entity_test', 'entity_test') ->setComponent('image_test', ['type' => 'image_image'])->save(); } /** Loading Loading @@ -198,4 +207,22 @@ public function testImageItemMalformed(): void { $this->assertEmpty($entity->image_test->height); } /** * Tests display_default. */ public function testDisplayDefaultValue(): void { $entity = EntityTest::create([ 'name' => $this->randomMachineName(), ]); $form_object = $this->container->get(EntityTypeManagerInterface::class)->getFormObject('entity_test', 'default'); \assert($form_object instanceof ContentEntityForm); $form_object->setEntity($entity); $form_display = EntityFormDisplay::collectRenderDisplay($entity, 'default'); \assert($form_display instanceof EntityFormDisplay); $form_state = new FormState(); $form_object->setFormDisplay($form_display, $form_state); $this->container->get(FormBuilderInterface::class)->buildForm($form_object, $form_state); self::assertEquals(1, $form_state->getValue(['image_test', 0, 'display'])); } } Loading
core/modules/image/src/Plugin/Field/FieldType/ImageItem.php +1 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ public static function defaultStorageSettings() { 'width' => NULL, 'height' => NULL, ], 'display_default' => TRUE, ] + parent::defaultStorageSettings(); } Loading
core/modules/image/tests/src/Kernel/ImageItemTest.php +28 −1 Original line number Diff line number Diff line Loading @@ -5,14 +5,20 @@ namespace Drupal\Tests\image\Kernel; use Drupal\Core\Database\Database; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormState; use Drupal\entity_test\Entity\EntityTest; use Drupal\field\Entity\FieldConfig; use Drupal\Tests\field\Kernel\FieldKernelTestBase; use Drupal\field\Entity\FieldStorageConfig; use Drupal\file\Entity\File; use Drupal\Tests\field\Kernel\FieldKernelTestBase; use Drupal\user\Entity\Role; /** Loading Loading @@ -92,6 +98,9 @@ protected function setUp(): void { ]); $this->image->save(); $this->imageFactory = $this->container->get('image.factory'); $this->container->get(EntityDisplayRepositoryInterface::class) ->getFormDisplay('entity_test', 'entity_test') ->setComponent('image_test', ['type' => 'image_image'])->save(); } /** Loading Loading @@ -198,4 +207,22 @@ public function testImageItemMalformed(): void { $this->assertEmpty($entity->image_test->height); } /** * Tests display_default. */ public function testDisplayDefaultValue(): void { $entity = EntityTest::create([ 'name' => $this->randomMachineName(), ]); $form_object = $this->container->get(EntityTypeManagerInterface::class)->getFormObject('entity_test', 'default'); \assert($form_object instanceof ContentEntityForm); $form_object->setEntity($entity); $form_display = EntityFormDisplay::collectRenderDisplay($entity, 'default'); \assert($form_display instanceof EntityFormDisplay); $form_state = new FormState(); $form_object->setFormDisplay($form_display, $form_state); $this->container->get(FormBuilderInterface::class)->buildForm($form_object, $form_state); self::assertEquals(1, $form_state->getValue(['image_test', 0, 'display'])); } }