You are here

public function EntityTypeManager::createHandlerInstance in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/EntityTypeManager.php \Drupal\Core\Entity\EntityTypeManager::createHandlerInstance()

Creates new handler instance.

Usually \Drupal\Core\Entity\EntityTypeManagerInterface::getHandler() is preferred since that method has additional checking that the class exists and has static caches.

Parameters

mixed $class: The handler class to instantiate.

\Drupal\Core\Entity\EntityTypeInterface $definition: The entity type definition.

Return value

object A handler instance.

Overrides EntityTypeManagerInterface::createHandlerInstance

2 calls to EntityTypeManager::createHandlerInstance()
EntityTypeManager::getHandler in core/lib/Drupal/Core/Entity/EntityTypeManager.php
Returns a handler instance for the given entity type and handler.
EntityTypeManager::getRouteProviders in core/lib/Drupal/Core/Entity/EntityTypeManager.php
Gets all route provider instances.

File

core/lib/Drupal/Core/Entity/EntityTypeManager.php, line 271

Class

EntityTypeManager
Manages entity type plugin definitions.

Namespace

Drupal\Core\Entity

Code

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->stringTranslation);
  }
  return $handler;
}