public function ContainerAwarePluginManager::createInstance in Service Container 7.2
Same name and namespace in other branches
- 7 src/Plugin/ContainerAwarePluginManager.php \Drupal\service_container\Plugin\ContainerAwarePluginManager::createInstance()
Creates a pre-configured instance of a plugin.
Parameters
string $plugin_id: The ID of the plugin being instantiated.
array $configuration: An array of configuration relevant to the plugin instance.
Return value
object A fully configured plugin instance.
Throws
\Drupal\Component\Plugin\Exception\PluginException If the instance cannot be created, such as if the ID is invalid.
Overrides FactoryInterface::createInstance
1 call to ContainerAwarePluginManager::createInstance()
- ContainerAwarePluginManager::getInstance in src/
Plugin/ ContainerAwarePluginManager.php - Gets a preconfigured instance of a plugin.
File
- src/
Plugin/ ContainerAwarePluginManager.php, line 61 - Contains \Drupal\service_container\Plugin\ContainerAwarePluginManager
Class
- ContainerAwarePluginManager
- Base class for plugin managers.
Namespace
Drupal\service_container\PluginCode
public function createInstance($plugin_id, array $configuration = array()) {
$plugin_definition_copy = $plugin_definition = $this
->getDefinition($plugin_id);
$plugin_class = static::getPluginClass($plugin_id, $plugin_definition);
// If the plugin provides a factory method, pass the container to it.
if (is_subclass_of($plugin_class, 'Drupal\\Core\\Plugin\\ContainerFactoryPluginInterface')) {
return $plugin_class::create($this->container, $configuration, $plugin_id, $plugin_definition);
}
$plugin_definition += array(
'arguments' => array(),
);
array_unshift($plugin_definition['arguments'], $plugin_definition_copy);
array_unshift($plugin_definition['arguments'], $plugin_id);
array_unshift($plugin_definition['arguments'], $configuration);
// Otherwise, create the plugin directly.
return $this->container
->createInstance($this->servicePrefix . $plugin_id, $plugin_definition);
}