class ContainerFactory in Plug 7
Plugin factory which passes a container to a create method.
Hierarchy
- class \Drupal\Component\Plugin\Factory\DefaultFactory implements FactoryInterface
- class \Drupal\Core\Plugin\Factory\ContainerFactory
Expanded class hierarchy of ContainerFactory
2 files declare their use of ContainerFactory
- DefaultPluginManager.php in lib/
Drupal/ Core/ Plugin/ DefaultPluginManager.php - Contains \Drupal\Core\Plugin\DefaultPluginManager.
- FruitPluginManager.php in modules/
plug_example/ src/ FruitPluginManager.php - Contains \Drupal\plug_example\FruitPluginManager.
File
- lib/
Drupal/ Core/ Plugin/ Factory/ ContainerFactory.php, line 14 - Contains \Drupal\Core\Plugin\Factory\ContainerFactory.
Namespace
Drupal\Core\Plugin\FactoryView source
class ContainerFactory extends DefaultFactory {
/**
* {@inheritdoc}
*/
public function createInstance($plugin_id, array $configuration = array()) {
$plugin_definition = $this->discovery
->getDefinition($plugin_id);
$plugin_class = static::getPluginClass($plugin_id, $plugin_definition, $this->interface);
// 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(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition);
}
// Otherwise, create the plugin directly.
return new $plugin_class($configuration, $plugin_id, $plugin_definition);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContainerFactory:: |
public | function |
Creates a pre-configured instance of a plugin. Overrides DefaultFactory:: |
|
DefaultFactory:: |
protected | property | The object that retrieves the definitions of the plugins that this factory instantiates. | |
DefaultFactory:: |
protected | property | Defines an interface each plugin should implement. | |
DefaultFactory:: |
public static | function | Finds the class relevant for a given plugin. | |
DefaultFactory:: |
public | function | Constructs a Drupal\Component\Plugin\Factory\DefaultFactory object. |