diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 128d21d..7d7eded 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -324,19 +324,7 @@ public function getHandler($entity_type, $handler_type) { if (!$class) { throw new InvalidPluginDefinitionException($entity_type, sprintf('The "%s" entity type did not specify a %s handler.', $entity_type, $handler_type)); } - if (is_subclass_of($class, 'Drupal\Core\Entity\EntityHandlerInterface')) { - $handler = $class::createInstance($this->container, $definition); - } - else { - $handler = new $class($definition); - } - if (method_exists($handler, 'setModuleHandler')) { - $handler->setModuleHandler($this->moduleHandler); - } - if (method_exists($handler, 'setStringTranslation')) { - $handler->setStringTranslation($this->translationManager); - } - $this->handlers[$handler_type][$entity_type] = $handler; + $this->handlers[$handler_type][$entity_type] = $this->createHandlerInstance($class, $definition); } return $this->handlers[$handler_type][$entity_type]; } @@ -344,6 +332,25 @@ public function getHandler($entity_type, $handler_type) { /** * {@inheritdoc} */ + public function createHandlerInstance($class, EntityTypeInterface $definition = null) { + if (is_subclass_of($class, 'Drupal\Core\Entity\EntityHandlerInterface')) { + $handler = $class::createInstance($this->container, $definition); + } + else { + $handler = new $class($definition); + } + if (method_exists($handler, 'setModuleHandler')) { + $handler->setModuleHandler($this->moduleHandler); + } + if (method_exists($handler, 'setStringTranslation')) { + $handler->setStringTranslation($this->translationManager); + } + return $handler; + } + + /** + * {@inheritdoc} + */ public function getBaseFieldDefinitions($entity_type_id) { // Check the static cache. if (!isset($this->baseFieldDefinitions[$entity_type_id])) { diff --git a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php index 8cf95ee..3199655 100644 --- a/core/lib/Drupal/Core/Entity/EntityManagerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php @@ -237,7 +237,7 @@ public function getFormObject($entity_type, $operation); public function hasHandler($entity_type, $handler_type); /** - * Creates a new handler instance. + * Creates a new handler instance for a entity type and handler type. * * @param string $entity_type * The entity type for this controller. @@ -252,6 +252,23 @@ public function hasHandler($entity_type, $handler_type); public function getHandler($entity_type, $handler_type); /** + * Creates new handler instance. + * + * Usually \Drupal\Core\Entity\EntityManagerInterface::getHandler() is + * preferred since this has additional checking that the class exists and + * has static caches. + * + * @param $class + * The handler class to instantiate. + * @param \Drupal\Core\Entity\EntityTypeInterface $definition + * The entity type definition. + * + * @return mixed + * A handler instance + */ + public function createHandlerInstance($class, EntityTypeInterface $definition = null); + + /** * Get the bundle info of an entity type. * * @param string $entity_type diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index 229dad1..8ce34d0 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -187,7 +187,7 @@ public function requiresEntityDataMigration(EntityTypeInterface $entity_type, En if (!class_exists($original_storage_class)) { return TRUE; } - $original_storage = $original_storage_class::createInstance(\Drupal::getContainer(), $entity_type); + $original_storage = $this->entityManager->createHandlerInstance($original_storage_class, $original); return $original_storage->hasData(); } return $this->storage->hasData();