The Drupal plugin system allows a particular module or subsystem to provide functionality in an extensible, object-oriented way. The controlling module defines the basic framework (interface) for the functionality, and other modules can create plugins (implementing the interface) with particular behaviors. Plugins are grouped into plugin types. Each plugin type is managed by a plugin manager service, which uses a plugin discovery method to discover provided plugins of that type and instantiate them using a plugin factory.
Plugins are one of the ways that module developers can write code that extends Drupal 8. The Drupal 8 Plugin API allows a module to provide functionality in an extensible, object-oriented way. Plugins are used to solve the problem where you need to allow one or more modules to provide additional "things" that implement the same interface but provide distinctly different functionality. In most cases, you also want to provide a site administrator with a list of those "things" so she can choose and configure the appropriate functionality for her use case.
Plugins are grouped into plugin types which are managed by a plugin manager service. As a module developer, knowing how to implement an existing plugin type should be considered required knowledge.
Many frameworks use the term "plugin" to describe a bundle of code and other elements that can be installed in order to get access to the features they provide. In Drupal these are called modules, and plugins are one of the ways a module can add new features.
- Define a custom block in a module
- Add a new field type, widget, or formatter
- Create a custom content entity type
- Define a new plugin type in order to allow other modules to extend your module's capabilities in the same way Drupal core is extended
Plugins were introduced in Drupal 8. The API isn't going to change until Drupal 9 at least, and even then will likely only see improvements. We don't think it's going to go away anytime soon. The process for implementing plugins is relatively unchanged since before Drupal 8 was released, so older examples are likely to still be relevant.