Plugin API overview
Plugins are small pieces of functionality that are swappable. Plugins that perform similar functionality are of the same plugin type.
Why Plugins?
Why plugins?
Attribute-based plugins
Plugins can use PHP attributes to register themselves and describe their metadata.
Create a custom attribute class
New plugin types should use a custom attributes class.
Annotations-based plugins
Most of the plugins in Drupal 8 will use annotations to register themselves and describe their metadata. Some of the plugins types provided
Annotation-Based Plugins in Views
Views uses annotation-based plugin discovery for much of the code in Drupal Core.
Creating your own Plugin Manager
The plugin manager is the central controlling class that defines how the plugins of a particular type will be discovered and instantiated.
Drupal Plugin discovery
Plugin discovery is the process by which Drupal finds plugins of a given type. A discovery method must be set for every plugin type
Discovery Decorators
A discovery decorator is a class which wraps another discovery mechanism in order to provide additional functionality (Wiki: Decorator
Plugin Definitions
Plugins play an integral role in facilitating user interface components. While the plugin system can be used for more situations than this
Plugin Contexts
Sometimes plugins require another object in order to perform their primary operation. This is known as plugin context. Using a practical
Plugin Derivatives
One of the most powerful portions of the plugin system is its ability to help inform the user interface components of a system and allow
Create your own custom annotation class
New plugin types should always use a custom annotation class, so at a later point you can add or change annotation keys or document them.
Creating a plugin that can be defined in themes
In general, plugins should not be defined in a class but in a custom module. There are some cases where plugins make sense in a Custom Theme