What is a Drupal plugin?

A plugin is a small piece of functionality that can be swapped in and out. Drupal uses plugins for blocks, field types, field widgets, field formatters, conditions, and many other extension points.

Plugins are defined as classes with annotations declaring their metadata. Drupal discovers plugins automatically and lets code request them by ID through a plugin manager.

The plugin system is powerful because it lets modules provide multiple implementations of the same interface. For example, the Block module defines a block plugin type, and every custom block class is a plugin. Writing custom plugins is one of the main ways modules extend Drupal. The pattern takes a little getting used to, but once understood it becomes a natural way to structure extensible code. Core and contrib both rely heavily on plugins.

Facebook
Twitter
LinkedIn
Pinterest