public function GroupRelationManager::createHandlerInstance in Group 2.0.x
Creates a new handler instance.
Using ::getHandler() is preferred since that method 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
string $plugin_id: The plugin ID for this handler.
string $handler_type: The handler type to create an instance for.
Return value
object A handler instance.
Overrides GroupRelationManagerInterface::createHandlerInstance
1 call to GroupRelationManager::createHandlerInstance()
- GroupRelationManager::getHandler in src/
Plugin/ Group/ Relation/ GroupRelationManager.php - Returns a handler instance for the given plugin and handler.
File
- src/
Plugin/ Group/ Relation/ GroupRelationManager.php, line 133
Class
- GroupRelationManager
- Manages GroupRelation plugin implementations.
Namespace
Drupal\group\Plugin\Group\RelationCode
public function createHandlerInstance($plugin_id, $handler_type) {
$definition = $this
->getDefinition($plugin_id);
$service_name = "group.relation_handler.{$handler_type}.{$definition['id']}";
if (!$this->container
->has($service_name)) {
throw new InvalidPluginDefinitionException($plugin_id, sprintf('The "%s" plugin did not specify a %s handler service (%s).', $plugin_id, $handler_type, $service_name));
}
$handler = $this->container
->get($service_name);
if (!is_subclass_of($handler, 'Drupal\\group\\Plugin\\Group\\RelationHandler\\RelationHandlerInterface')) {
throw new InvalidPluginDefinitionException($plugin_id, 'Trying to instantiate a handler that does not implement \\Drupal\\group\\Plugin\\Group\\RelationHandler\\RelationHandlerInterface.');
}
$handler
->init($plugin_id, $definition);
return $handler;
}