You are here

public function GroupContentEnablerManager::createHandlerInstance in Group 8

Creates new handler instance.

\Drupal\group\Plugin\GroupContentEnablerManagerInterface::getHandler() is preferred since that method has additional checking that the class exists and has static caches.

@internal Marked as internal because the plugin definitions will become classes in a future release to further mimic the entity type system. Do not call this directly.

Parameters

mixed $class: The handler class to instantiate.

string $plugin_id: The ID of the plugin the handler is for.

array $definition: The plugin definition.

Return value

object A handler instance.

Overrides GroupContentEnablerManagerInterface::createHandlerInstance

1 call to GroupContentEnablerManager::createHandlerInstance()
GroupContentEnablerManager::getHandler in src/Plugin/GroupContentEnablerManager.php
Returns a handler instance for the given plugin and handler.

File

src/Plugin/GroupContentEnablerManager.php, line 150

Class

GroupContentEnablerManager
Manages GroupContentEnabler plugin implementations.

Namespace

Drupal\group\Plugin

Code

public function createHandlerInstance($class, $plugin_id, array $definition = NULL) {
  if (!is_subclass_of($class, 'Drupal\\group\\Plugin\\GroupContentHandlerInterface')) {
    throw new InvalidPluginDefinitionException($plugin_id, 'Trying to instantiate a handler that does not implement \\Drupal\\group\\Plugin\\GroupContentHandlerInterface.');
  }
  $handler = $class::createInstance($this->container, $plugin_id, $definition);
  if (method_exists($handler, 'setModuleHandler')) {
    $handler
      ->setModuleHandler($this->moduleHandler);
  }
  return $handler;
}