Quantcast
Viewing all articles
Browse latest Browse all 292913

Plugin factories should not depend on $discovery. ContainerFactory can become a service.

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.


Viewing all articles
Browse latest Browse all 292913

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>