add a plugin type ID

Created on 27 September 2024, 6 months ago

Problem/Motivation

We have in core a concept of a plugin type, but there is no way to refer to that plugin type, or obtain the manager of that plugin type.

This presumably wasn't added to the plugin system because unlike entities, where we need to work with the entity type, plugins of different types do not mix.

However, we've already semi-implemented a concept of plugin type ID in at least two places:

1. For FilteredPluginManagerInterface, those plugin managers which want to provide filtering capabilities need to implement a getType() method. In effect, that means that *some* plugin types have a type ID, e.g. for block plugins:

  protected function getType() {
    return 'block';
  }

However, you can only get the type ID if you have the manager. You can't go the other way.

2. The config validation system has recently added a way for a config schema to validate that a plugin exists. For this, it needs to identify the plugin type. In config schema, that's done by specifying the manager and the interface:

      constraints:
        PluginExists:
          manager: plugin.manager.block
          interface: Drupal\Core\Block\BlockPluginInterface

Steps to reproduce

Proposed resolution

Unify and extend these systems by defining a type ID for all plugin types.

Modules that define a plugin type should have a MODULE.plugin_types.yml file which defines the type ID, its service manager, and the plugin interface.

Potential follow-ons

With the type and the interface defined, there is potential to move code from individual plugin manager classes to the DefaultPluginManager base class.

In simple cases, it would even be possible to remove the plugin manager class entirely and have it derived -- see #3029291: add a generic plugin manager class for a POC in Plugin module.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Feature request
Status

Active

Version

11.0 🔥

Component

plugin system

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024