Exposing your plugin types
The Plugin module describes a format for telling other projects about the plugin types your module provides. This is useful if those projects provide generic features for any plugin type, such as Drupal core's cache clearing mechanisms, or the Plugin module's plugin field type, which can store instances of plugins of any type.
Exposing plugin types
Modules can expose their plugin types through $module.plugin_type.yml files in their root folders, where $module is the name of the module itself. The files' contents are objects. Top-level keys are plugin type IDs (strings), and the values are objects. The only required object property is class, which must be the fully qualified name of a class that implements \Drupal\plugin\PluginType\PluginTypeInterface, or be left empty to default to \Drupal\plugin\PluginType\PluginType. All other properties depend on the class, but the default class takes the following:
label(required): the human-readable US English plugin type label.description(optional): the human-readable US English plugin descriptionplugin_manager_service_id(required): the ID of the plugin type's plugin manager in the service containerplugin_definition_decorator_class(required) the fully qualified name of a class that implements\Drupal\plugin\PluginDefinition\PluginDefinitionDecoratorInterfaceif the original plugin definitions do not implement\Drupal\plugin\PluginDefinition\PluginDefinitionInterface. Most plugin types use array definitions, and they can use\Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecoratorhere.operations_provider_class(optional): the fully qualified name of a class that implements\Drupal\plugin\PluginType\PluginTypeOperationsProviderInterface. Defaults to\Drupal\plugin\PluginType\DefaultPluginTypeOperationsProvider
Example:
payment_method:
label: Payment method
plugin_manager_service_id: plugin.manager.payment.method
plugin_definition_decorator_class: \Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecorator
operations_provider_class: \Drupal\payment\Plugin\Payment\Method\PaymentMethodOperationsProvider
Exposing plugin configuration schemas
Configuration schemas are used to inspect module's configuration, and to provide features like configuration translation. If you expose a plugin type, a schema for its configuration MAY be provided. Not providing a schema will simply mean that any configuration of plugins of your type that is stored by other modules will not benefit from the aforementioned features.
If a schema is provided, its name MUST be like plugin.plugin_configuration.$plugin_type_id.$plugin_id, where $plugin_type_id is the plugin type ID as specified in $module.plugin_type.yml and $plugin_id is the ID of a specific plugin.
An example for a plugin type called foo and a plugin with ID bar:
plugin.plugin_configuration.foo.bar:
type: mapping
mapping:
label:
label: Label
type: label
do_something:
label: Do something useful
type: boolean
See #2629640: Configuration schema aliases for exposing existing schemas using this format.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion