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

Created on 20 April 2013, almost 12 years ago
Updated 10 February 2025, 13 days ago

Follow-up to #1863816: 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.
- NEW (#11): Avoid serialization issues.

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):

  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.

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

plugin system

Created by

πŸ‡©πŸ‡ͺGermany donquixote

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • VDC

    Related to the Views in Drupal Core initiative.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024