diff -u b/core/modules/field/field.module b/core/modules/field/field.module --- b/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -427,0 +428,9 @@ + +/** + * Implements hook_modules_uninstalled(). + */ +function field_modules_uninstalled($modules) { + /** @var \Drupal\field\EntityDisplayRebuilder $display_rebuilder */ + $display_rebuilder = \Drupal::service('field.entity_display_rebuilder'); + $display_rebuilder->rebuildAllEntityTypeDisplays(TRUE); +} diff -u b/core/modules/field/src/EntityDisplayRebuilder.php b/core/modules/field/src/EntityDisplayRebuilder.php --- b/core/modules/field/src/EntityDisplayRebuilder.php +++ b/core/modules/field/src/EntityDisplayRebuilder.php @@ -49,6 +49,22 @@ } /** + * Rebuild displays for all Entity Types. + * + * @param bool $include_default_displays + * Add 'default' displays. Defaults to FALSE. + * + * @throws \Drupal\Core\Entity\EntityStorageException + * In case of failures an exception is thrown. + */ + public function rebuildAllEntityTypeDisplays($include_default_displays = FALSE) { + $entity_types = $this->entityTypeManager->getDefinitions(); + foreach ($entity_types as $entity_type_id => $entity_type_definition) { + $this->rebuildEntityTypeDisplays($entity_type_id, $include_default_displays); + } + } + + /** * Rebuild displays for single Entity Type. * * @param string $entity_type_id diff -u b/core/modules/field/tests/src/Kernel/DisplayModeUpdateTest.php b/core/modules/field/tests/src/Kernel/DisplayModeUpdateTest.php --- b/core/modules/field/tests/src/Kernel/DisplayModeUpdateTest.php +++ b/core/modules/field/tests/src/Kernel/DisplayModeUpdateTest.php @@ -117,2 +117,32 @@ + /** + * Ensure display modes are updated after uninstalling Language module. + */ + public function testDisplayModeConfigAfterUninstall() { + $default_view_display = 'core.entity_view_display.entity_test.entity_test.default'; + $default_form_display = 'core.entity_form_display.entity_test.entity_test.default'; + $foobar_view_display = 'core.entity_view_display.entity_test.entity_test.foobar'; + $foobar_form_display = 'core.entity_form_display.entity_test.entity_test.foobar'; + + // Install language module. + \Drupal::service('module_installer')->install(['language']); + + // 1. Validate that "langcode" key is there. + $this->assertArrayHasKey('langcode', \Drupal::config($default_view_display)->get('hidden')); + $this->assertArrayHasKey('langcode', \Drupal::config($default_form_display)->get('content')); + $this->assertArrayHasKey('langcode', \Drupal::config($foobar_view_display)->get('hidden')); + $this->assertArrayHasKey('langcode', \Drupal::config($foobar_form_display)->get('content')); + + // 2. Uninstall language module. + $this->installSchema('user', ['users_data']); + \Drupal::service('module_installer')->uninstall(['language']); + + // 3. Test that "langcode" key is removed from field config. + $this->assertArrayNotHasKey('langcode', \Drupal::config($default_view_display)->get('hidden')); + $this->assertArrayNotHasKey('langcode', \Drupal::config($default_form_display)->get('content')); + $this->assertArrayNotHasKey('langcode', \Drupal::config($foobar_view_display)->get('hidden')); + $this->assertArrayNotHasKey('langcode', \Drupal::config($foobar_form_display)->get('content')); + + } + }