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.
- Drupal 8 Module Development Guide
- The Drupal 8 Module Development Guide has 9 tutorials covering plugins. We suggest you start with What Are Plugins?. Use these tutorials to familiarize yourself with the concepts and terminology used in the Plugin API and how the system works. Afterwards, use Implement a Plugin of Any Type as a resource to jog your memory when implementing a plugin.
- Introduce the concept of Annotations, explain how they are used in Drupal, and show some examples. Working with the Plugin API requires understanding how Annotations work in PHP.