What is a Drupal plugin?
A plugin allows a developer to build an interface for their application. It offers good performance when reading and writing compared to other mechanisms, and allows complex backup structures to be defined (using annotations). A plugin is a set of code defined according to a concept that allows specific needs to be met. To create a plugin, you need to create a plugin manager (which defines the schema to be followed), then index this new plugin.
The plugin manager is generally wired to DefaultPluginManager.
Plugins can be created in src/Plugin/$plugin_type/$plugin_name or in src/Plugin/$moduleName/$plugin_type/$plugin_name.
Annotations are generally used to register a plugin.
How does plugin discovery work?
How do you instantiate a given plugin?
What are the best practices for facilitating the implementation of your type of plugins by others?
How do you include your new plugin manager in the Drupal service container?
Important concepts for better understanding the creation of the plugin manager:
Drupal\Core\Plugin\Factory\ContainerFactory
...
return $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition);
Ressources :
- Unraveling the Drupal 8 Plugin System
- Drupal 8 Custom Plugin Types , (suite), github.
- Custom Plugin Type In Drupal 8*