diff --git a/core/modules/field_layout/field_layout.install b/core/modules/field_layout/field_layout.install index 6f94674..2ad8d8e 100644 --- a/core/modules/field_layout/field_layout.install +++ b/core/modules/field_layout/field_layout.install @@ -24,3 +24,10 @@ function field_layout_install() { // Invalidate the render cache since all content will now have a layout. Cache::invalidateTags(['rendered']); } + +/** + * Implements hook_uninstall(). + */ +function field_layout_uninstall() { + \Drupal::state()->set('field_layout_being_uninstalled', TRUE); +} diff --git a/core/modules/field_layout/src/Entity/FieldLayoutEntityDisplayTrait.php b/core/modules/field_layout/src/Entity/FieldLayoutEntityDisplayTrait.php index e6fd168..0b4e01c 100644 --- a/core/modules/field_layout/src/Entity/FieldLayoutEntityDisplayTrait.php +++ b/core/modules/field_layout/src/Entity/FieldLayoutEntityDisplayTrait.php @@ -77,7 +77,9 @@ protected function init() { * Overrides \Drupal\Core\Entity\EntityDisplayBase::preSave(). */ public function preSave(EntityStorageInterface $storage) { - $this->ensureLayout(); + if (!\Drupal::state()->get('field_layout_being_uninstalled')) { + $this->ensureLayout(); + } parent::preSave($storage); @@ -85,7 +87,9 @@ public function preSave(EntityStorageInterface $storage) { // stored as third party settings, this will be handled by the code in // \Drupal\Core\Config\Entity\ConfigEntityBase::preSave() that handles // \Drupal\Core\Entity\EntityWithPluginCollectionInterface. - $this->setLayout($this->getLayout()); + if (!\Drupal::state()->get('field_layout_being_uninstalled')) { + $this->setLayout($this->getLayout()); + } } /** diff --git a/core/modules/field_layout/tests/src/Kernel/FieldLayoutEntityDisplayTest.php b/core/modules/field_layout/tests/src/Kernel/FieldLayoutEntityDisplayTest.php index edfb19b..41bb59d 100644 --- a/core/modules/field_layout/tests/src/Kernel/FieldLayoutEntityDisplayTest.php +++ b/core/modules/field_layout/tests/src/Kernel/FieldLayoutEntityDisplayTest.php @@ -15,7 +15,7 @@ class FieldLayoutEntityDisplayTest extends KernelTestBase { /** * {@inheritdoc} */ - protected static $modules = ['layout_discovery', 'field_layout', 'entity_test', 'field_layout_test']; + protected static $modules = ['layout_discovery', 'field_layout', 'entity_test', 'field_layout_test', 'system']; /** * @covers ::preSave @@ -181,6 +181,39 @@ public function testPreSave() { ]; $this->assertEntityValues($expected, $entity_display); + + $expected = [ + 'langcode' => 'en', + 'status' => TRUE, + 'dependencies' => [ + 'module' => [ + 'entity_test', + ], + ], + 'third_party_settings' => [ + 'entity_test' => [ + 'foo' => 'bar', + ], + ], + 'id' => 'entity_test.entity_test.default', + 'targetEntityType' => 'entity_test', + 'bundle' => 'entity_test', + 'mode' => 'default', + 'content' => [ + 'foo' => [ + 'type' => 'visible', + 'region' => 'content', + ], + ], + 'hidden' => [ + 'bar' => TRUE, + ], + ]; + + $this->container->get('module_installer')->uninstall(['field_layout']); + $entity_storage = $this->container->get('entity_type.manager')->getStorage('entity_view_display'); + $entity_display = $entity_storage->load('entity_test.entity_test.default'); + $this->assertEntityValues($expected, $entity_display); } /**