Follow-up to #1863816: Change notice: Allow plugins to have services injected
Goals:
- Eliminate the \Drupal::getContainer()
in ContainerFactory.
- Improve the distribution of responsibilities between plugin manager components.
- Avoid a direct dependency from a plugin manager to the container.
Proposed plan:
- Re-distribute the responsibilities of PluginManager and PluginFactory, so that the factory does not need a $discovery.
- Let the ContainerFactory have a $container injected, instead of calling \Drupal::getContainer()
.
- Now that the container factory does not depend on $discovery anymore, it can become a service.
- Let PluginManager have the factory injected via DIC, instead of creating it.
The heart of all this (in PluginManager):
<?php
public function createInstance($plugin_id, array $configuration = array()) {
$plugin_definition = $this->discovery->getDefinition($plugin_id);
return $this->factory->createInstance($plugin_id, $plugin_definition, $configuration);
}
?>
Problem:
The signature of ContainerFactory::createInstance() would be incompatible with the current signature of FactoryInterface::createInstance(). This means, we either have to change this for all plugins, or we have to allow two different types of factories.