Consider adding a PLUGIN_ID const to each plugin class and consistently using that in calling code

Created on 22 June 2025, 1 day ago

Problem/Motivation

Throughout core we make heavy use of plugins.
When initiating plugins we typically pass the plugin ID to a plugin manager.

e.g.

\Drupal::service('plugin.manager.block')->createInstance('system_breadcrumb_block')

Each of these Plugin IDs have special meaning, they're not just a string.
Detecting usages of these IDs vs a string requires grepping the code and eliminating false positives.
Misspelling the plugin ID can lead to plugin not found exceptions.

Proposed resolution

Now that we have attributes for plugin discovery, we can replace hard-coded strings with constants.
Attributes are smart enough to be able to detect that self::PLUGIN_ID refers to the object with the attribute.

  1. Decide we want to do this
  2. For all plugin classes in core (except entity-types) add a public const string PLUGIN_ID = '{the plugin id here}
  3. Replace all usage of the string with references to the constant
  4. Update the attribute to use self::PLUGIN_ID
  5. Do the same for entity-types, but instead of using PLUGIN_ID, use ENTITY_TYPE_ID instead

Remaining tasks

All of the above

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

plugin system

Created by

πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024