diff -u b/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php b/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php --- b/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php +++ b/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php @@ -130,7 +130,7 @@ break; case static::DEFINITION_DELETED: - $this->entityManager->onFieldStorageDefinitionDelete($storage_definitions[$field_name]); + $this->entityManager->onFieldStorageDefinitionDelete($original_storage_definitions[$field_name]); break; } } @@ -207,7 +207,7 @@ * @return bool * TRUE if storage schema changes are required, FALSE otherwise. */ - protected function requiresEntityStorageSchemaChanges($entity_type, $original) { + protected function requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original) { $storage = $this->entityManager->getStorage($entity_type->id()); return ($storage instanceof EntityStorageSchemaInterface) && $storage->requiresEntityStorageSchemaChanges($entity_type, $original); } diff -u b/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManagerInterface.php --- b/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManagerInterface.php @@ -16,12 +16,14 @@ * perform complex or long-running logic in response to the change. For * example, a SQL-based storage handler may need to update the database schema. * - * The entity manager tracks both the current code-defined definitions and the - * most recent definitions that entity handlers have had a chance to react to, - * and implements \Drupal\Core\Entity\EntityTypeListenerInterface and - * \Drupal\Core\Field\FieldStorageDefinitionListenerInterface for bringing the - * latter up to date with the former, but makes no decisions about when to - * invoke those events. This interface is for managing that. + * To support this, \Drupal\Core\Entity\EntityManagerInterface has methods to + * retrieve the last installed definitions as well as the definitions specified + * by the current codebase. It also has create/update/delete methods to bring + * the former up to date with the latter. + * + * However, it is not the responsibility of the entity manager to decide how to + * report the differences or when to apply each update. This interface is for + * managing that. * * @see \Drupal\Core\Entity\EntityManagerInterface::getDefinition() * @see \Drupal\Core\Entity\EntityManagerInterface::getLastInstalledDefinition() diff -u b/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php --- b/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -9,6 +9,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface; use Drupal\Core\Page\DefaultHtmlPageRenderer; @@ -61,6 +62,13 @@ protected $account; /** + * The entity definition update manager. + * + * @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface + */ + protected $entityDefinitionUpdateManager; + + /** * Constructs a new UpdateController. * * @param \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface $key_value_expirable_factory @@ -73,13 +81,16 @@ * The module handler. * @param \Drupal\Core\Session\AccountInterface $account * The current user. + * @param \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $entity_definition_update_manager + * The entity definition update manager. */ - public function __construct(KeyValueExpirableFactoryInterface $key_value_expirable_factory, CacheBackendInterface $cache, StateInterface $state, ModuleHandlerInterface $module_handler, AccountInterface $account) { + public function __construct(KeyValueExpirableFactoryInterface $key_value_expirable_factory, CacheBackendInterface $cache, StateInterface $state, ModuleHandlerInterface $module_handler, AccountInterface $account, EntityDefinitionUpdateManagerInterface $entity_definition_update_manager) { $this->keyValueExpirableFactory = $key_value_expirable_factory; $this->cache = $cache; $this->state = $state; $this->moduleHandler = $module_handler; $this->account = $account; + $this->entityDefinitionUpdateManager = $entity_definition_update_manager; } /** @@ -91,7 +102,8 @@ $container->get('cache.default'), $container->get('state'), $container->get('module_handler'), - $container->get('current_user') + $container->get('current_user'), + $container->get('entity.definition_update_manager') ); } @@ -286,9 +298,9 @@ } // If there are entity definition updates, display their summary. - if (\Drupal::service('entity.definition_update_manager')->needsUpdates()) { + if ($this->entityDefinitionUpdateManager->needsUpdates()) { $entity_build = array(); - $summary = \Drupal::service('entity.definition_update_manager')->getChangeSummary(); + $summary = $this->entityDefinitionUpdateManager->getChangeSummary(); foreach ($summary as $entity_type_id => $items) { $entity_update_key = 'entity_type_updates_' . $entity_type_id; $entity_build[$entity_update_key] = array( @@ -523,7 +535,7 @@ // First of all perform entity definition updates, which will update // storage schema if needed, so that module update functions work with // the correct entity schema. - if (\Drupal::service('entity.definition_update_manager')->needsUpdates()) { + if ($this->entityDefinitionUpdateManager->needsUpdates()) { $operations[] = array('update_entity_definitions', array('system', '0 - Update entity definitions')); }