diff --git a/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php b/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php index 070224b..e67629b 100644 --- a/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php +++ b/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php @@ -90,14 +90,6 @@ public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $ // definition need to use the last installed entity type schema. if ($storage instanceof SqlContentEntityStorage && ($last_installed_entity_type = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id))) { - // If the field being created is the ID field make sure the ID key is - // registered correctly. - $id_key = $this->entityTypeManager->getDefinition($entity_type_id)->getKey('id'); - if (!$last_installed_entity_type->hasKey('id') && ($storage_definition->getName() === $id_key)) { - $keys = $last_installed_entity_type->getKeys(); - $keys['id'] = $id_key; - $last_installed_entity_type->set('entity_keys', $keys); - } $storage->setEntityType($last_installed_entity_type); } diff --git a/core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.install b/core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.install index c56d5b5..a165267 100644 --- a/core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.install +++ b/core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.install @@ -6,18 +6,24 @@ */ /** - * Implements hook_install(). + * Implements hook_module_preinstall(). */ -function contact_storage_test_install() { - $entity_manager = \Drupal::entityManager(); - $entity_type = $entity_manager->getDefinition('contact_message'); - - // Recreate the original entity type definition, in order to notify the - // manager of what changed. The change of storage backend will trigger - // schema installation. +function contact_storage_test_module_preinstall($module) { + // This test module alters the definition of the 'contact_message' entity type + // so we need to inform the system about our changes before additional field + // storage definitions are added by the module installer. // @see contact_storage_test_entity_type_alter() - $original = clone $entity_type; - $original->setStorageClass('Drupal\Core\Entity\ContentEntityNullStorage'); + // @see contact_storage_test_entity_base_field_info + if ($module === 'contact_storage_test') { + $definition_update_manager = \Drupal::entityDefinitionUpdateManager(); + $entity_type = $definition_update_manager->getEntityType('contact_message'); + + $entity_type->setStorageClass('\Drupal\Core\Entity\Sql\SqlContentEntityStorage'); + $keys = $entity_type->getKeys(); + $keys['id'] = 'id'; + $entity_type->set('entity_keys', $keys); + $entity_type->set('base_table', 'contact_message'); - $entity_manager->onEntityTypeUpdate($entity_type, $original); + $definition_update_manager->updateEntityType($entity_type); + } } diff --git a/core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.module b/core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.module index cef976c..fbcd362 100644 --- a/core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.module +++ b/core/modules/contact/tests/modules/contact_storage_test/contact_storage_test.module @@ -33,8 +33,8 @@ function contact_storage_test_entity_base_field_info(EntityTypeInterface $entity */ function contact_storage_test_entity_type_alter(array &$entity_types) { /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ - // Set the controller class for nodes to an alternate implementation of the - // Drupal\Core\Entity\EntityStorageInterface interface. + // Set the controller class for contact messages to an alternate + // implementation of the \Drupal\Core\Entity\EntityStorageInterface interface. $entity_types['contact_message']->setStorageClass('\Drupal\Core\Entity\Sql\SqlContentEntityStorage'); $keys = $entity_types['contact_message']->getKeys(); $keys['id'] = 'id';