How to Create a Custom Plugin in Drupal Using Attribute-Based Plugin System

How to Create a Custom Plugin in Drupal Using Attribute-Based Plugin System

Jo Fitzgerald’s detailed tutorial walks developers through the steps to build a custom plugin in Drupal using modern, attribute-based methods introduced in Drupal 10.2. The article explains the five required components of a plugin system: an interface, an optional base class, a PHP attribute for metadata, a plugin manager class, and the actual plugin implementation. It emphasises best practices, including defining interfaces for consistent behaviour and using base classes to share functionality.

The guide highlights how plugins are now defined using PHP attributes, replacing older annotation-based approaches. Jo details how to register the plugin manager as a service and how to implement the manager class by extending DefaultPluginManager. An example plugin is provided, showing how to use a custom attribute to declare plugin metadata like ID and label. The post also covers how to instantiate and use the plugin via the service container or dependency injection.

Jo references real-world projects—such as Token Modifier, Metatag Link Preview, and a proposed improvement to Markdown Easy—to illustrate the power and flexibility of Drupal’s plugin architecture. The article sets the stage for a follow-up post on using Drush Generate to streamline plugin manager creation.

Reference: How to Create a Custom Drupal plugin (11 August 2025)

Disclosure: This content is produced with the assistance of AI.

Disclaimer: The opinions expressed in this story do not necessarily represent that of TheDropTimes. We regularly share third-party blog posts that feature Drupal in good faith. TDT recommends Reader's discretion while consuming such content, as the veracity/authenticity of the story depends on the blogger and their motives. 

Note: The vision of this web portal is to help promote news and stories around the Drupal community and promote and celebrate the people and organizations in the community. We strive to create and distribute our content based on these content policy. If you see any omission/variation on this please reach out to us at #thedroptimes channel on Drupal Slack and we will try to address the issue as best we can.

Related People

Upcoming Events

Latest Opportunities