Converting Drupal Plugins from Annotations to Attributes
- Source: The big plugin attribute change-over made easy by Joachim (02 Sep 2025)
Joachim explains how Drupal developers can transition plugin types from annotations to attributes ahead of Drupal 12, where attributes will be required. While annotations remain supported until Drupal 13, adopting attributes sooner unlocks cleaner definitions, IDE autocompletion, PHP constant support, and easier translations. Drupal Rector can convert individual plugins, but converting plugin types requires additional tooling.
Module Builder’s new Adoption feature (in Drupal Code Builder 4.5.4) streamlines this process by importing existing module code, enabling developers to switch discovery types to attribute-based plugins, and regenerating the necessary files. Once plugin types are attribute-enabled, Rector can handle bulk conversions of individual plugins. Developers must then tidy up attribute formatting—using regex fixes where Rector falls short. Joachim stresses running plugin tests after conversion to ensure stability before Drupal 12’s attribute requirement takes effect.

