public function EntityTypeManager::getHandler

public EntityTypeManager::getHandler($entity_type, $handler_type)

Creates a new handler instance for a entity type and handler type.

Parameters

string $entity_type: The entity type for this handler.

string $handler_type: The handler type to create an instance for.

Return value

object A handler instance.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

Overrides EntityTypeManagerInterface::getHandler

File

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

Class

EntityTypeManager
Manages entity type plugin definitions.

Namespace

Drupal\Core\Entity

Code

public function getHandler($entity_type, $handler_type) {
  if (!isset($this->handlers[$handler_type][$entity_type])) {
    $definition = $this->getDefinition($entity_type);
    $class = $definition->getHandlerClass($handler_type);
    if (!$class) {
      throw new InvalidPluginDefinitionException($entity_type, sprintf('The "%s" entity type did not specify a %s handler.', $entity_type, $handler_type));
    }
    $this->handlers[$handler_type][$entity_type] = $this->createHandlerInstance($class, $definition);
  }

  return $this->handlers[$handler_type][$entity_type];
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityTypeManager.php/function/EntityTypeManager::getHandler/8.1.x