During some of the work on views we came to the conclusion that it would be helpful to find out which module provides what kind of plugins.

This is just pseudo-code but for example plugin_fetch_plugin_types('aggregator', 'aggregator') would return array('fetcher'), plugin_fetch_plugin_types('ctools', 'views') would probably return array('style', 'field') one day.

Do you think such a function would be helpful in general?

Comments

xano’s picture

Issue summary: View changes

Yes! If, in the future, we will also get things like #2458789: Introduce PluginDefinitionInterface, we have access to all plugins of all plugin types in the code.

In the meantime, what about we something similar to plugin_manager_cache_clear? We could extend PluginManagerPass with support for that tag and plugin_manager and use it for listing all plugin managers and cache clearing at the same time.

dawehner’s picture

I'd say that both, the plugin cache clear, as well as the potential plugin type listing service could leverage the same information.

xano’s picture

Given a service ID, can we find out which module defined it? I dug through how DrupalKernel discovers all services, but apart from the fact that on every service definition it sets the file it was defined in–which is partly useful at best–I can't really see any useful metadata.

dawehner’s picture

Not really at the moment ...

xano’s picture

Status: Active » Needs review
StatusFileSize
new8.25 KB

Status: Needs review » Needs work

The last submitted patch, 5: drupal_1739280_5.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new402 bytes
new8.25 KB

Xano queued 7: drupal_1739280_7.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 7: drupal_1739280_7.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new8.45 KB

Re-roll.

dawehner’s picture

  1. +++ b/core/core.services.yml
    @@ -1354,9 +1354,10 @@ services:
    +  plugin.manager_collection:
    +    class: Drupal\Component\Plugin\PluginManagerCollection
    
    +++ b/core/lib/Drupal/Core/Plugin/PluginManagerPass.php
    @@ -20,9 +20,16 @@ class PluginManagerPass implements CompilerPassInterface {
    +        // @todo Consider throwing exceptions when the services are tagged, but
    +        //   don't implement the required interfaces.
    +        if (is_subclass_of($definition->getClass(), '\Drupal\Component\Plugin\PluginManagerInterface')) {
    +          $plugin_manager_collection_definition->addMethodCall('setPluginManager', [new Reference($service_id)]);
    +        }
    

    Urgs, so once you would use that particular class somewhere you would initialize all the plugin managers. Maybe make at least plugin.manager_collection lazy?

  2. +++ b/core/lib/Drupal/Component/Plugin/PluginManagerCollection.php
    @@ -0,0 +1,78 @@
    +<?php
    +/**
    
    +++ b/core/lib/Drupal/Component/Plugin/PluginManagerCollectionInterface.php
    @@ -0,0 +1,81 @@
    +<?php
    +/**
    + * @file
    

    Nitpick: missing empty line

  3. +++ b/core/lib/Drupal/Component/Plugin/PluginManagerCollectionInterface.php
    @@ -0,0 +1,81 @@
    +
    +/**
    + * Defines a plugin manager collection.
    + */
    +interface PluginManagerCollectionInterface {
    

    It would be great to document the purpose of this interface :)

xano’s picture

An alternative would be to inject the service IDs and the container. The downside of that is that it tightly couples the class with Symfony's DependencyInjection component and we'd have to add some runtime validation to make sure the service IDs do indeed reference instances of classes that implement PluginManagerInterface.

xano’s picture

The suggestion in #12 also means this code would have to be moved from \Drupal\Component to \Drupal\Core.

dawehner’s picture

+++ b/core/core.services.yml
@@ -1354,9 +1354,10 @@ services:
+  plugin.manager_collection:
+    class: Drupal\Component\Plugin\PluginManagerCollection

At least we should make the plugin.manager_collection lazy, so we don't inject all the things unless we really want to do something with it.

xano’s picture

What exactly does lazy mean in this case?

xano’s picture

See #2513946: Add plugin type discovery for a more comprehensive contrib solution.

xano’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Needs review » Postponed
xano’s picture

Status: Postponed » Active

I propose we include Plugin's solution in core, as described in PLUGIN_TYPES.md. This means modules should expose their plugin types using $module.plugin_type.yml files in their root folders (example). PluginTypeManager uses PluginType as the default plugin type 'definition' class, but as you can see that's pluggable, and as such plugin managers can be defined in custom ways.

If this approach is seen as viable, I can work on a patch.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +stale-issue-cleanup

Thank you for sharing your idea for improving Drupal.

We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. 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!

smustgrave’s picture

Wanted to bump this 1 more time.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.