Skip to content
Snippets Groups Projects
Verified Commit 72658312 authored by Dave Long's avatar Dave Long
Browse files

Issue #3513317 by annmarysruthy, larowlan, wim leers:...

Issue #3513317 by annmarysruthy, larowlan, wim leers: ImageItem::defaultStorageSettings() should override display_default
parent 96df9ddb
Branches
Tags
3 merge requests!3478Issue #3337882: Deleted menus are not removed from content type config,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!579Issue #2230909: Simple decimals fail to pass validation
Pipeline #453934 canceled
......@@ -72,6 +72,7 @@ public static function defaultStorageSettings() {
'width' => NULL,
'height' => NULL,
],
'display_default' => TRUE,
] + parent::defaultStorageSettings();
}
......
......@@ -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;
/**
......@@ -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();
}
/**
......@@ -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']));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment