Default plugin factory.
Instantiates plugin instances by passing the full configuration array as a single constructor argument. Plugin types wanting to support plugin classes with more flexible constructor signatures can do so by using an alternate factory such as Drupal\Component\Plugin\Factory\ReflectionFactory.
Expanded class hierarchy of DefaultFactory
class DefaultFactory implements FactoryInterface {
/**
* The object that retrieves the definitions of the plugins that this factory instantiates.
*
* The plugin definition includes the plugin class and possibly other
* information necessary for proper instantiation.
*
* @var Drupal\Component\Plugin\Discovery\DiscoveryInterface
*/
protected $discovery;
/**
* Constructs a Drupal\Component\Plugin\Factory\DefaultFactory object.
*/
public function __construct(DiscoveryInterface $discovery) {
$this->discovery = $discovery;
}
/**
* Implements Drupal\Component\Plugin\Factory\FactoryInterface::createInstance().
*/
public function createInstance($plugin_id, array $configuration) {
$plugin_class = $this
->getPluginClass($plugin_id);
return new $plugin_class($configuration, $plugin_id, $this->discovery);
}
/**
* Finds the class relevant for a given plugin.
*
* @param array $plugin_id
* The id of a plugin.
*
* @return string
* The appropriate class name.
*/
protected function getPluginClass($plugin_id) {
$plugin_definition = $this->discovery
->getDefinition($plugin_id);
if (empty($plugin_definition['class'])) {
throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id));
}
$class = $plugin_definition['class'];
if (!class_exists($class)) {
throw new PluginException(sprintf('Plugin (%s) instance class "%s" does not exist.', $plugin_id, $class));
}
return $class;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultFactory:: |
protected | property | The object that retrieves the definitions of the plugins that this factory instantiates. | |
DefaultFactory:: |
public | function |
Implements Drupal\Component\Plugin\Factory\FactoryInterface::createInstance(). Overrides FactoryInterface:: |
4 |
DefaultFactory:: |
protected | function | Finds the class relevant for a given plugin. | |
DefaultFactory:: |
public | function | Constructs a Drupal\Component\Plugin\Factory\DefaultFactory object. |