Use constants for plugin IDs

Created on 13 July 2024, about 2 months ago
Updated 14 July 2024, about 2 months ago

Problem/Motivation

Currently plugin IDs are defined as string literals in plugin annotation/attributes. Any time you need to reference plugin you need to make sure you correctly type its ID.

Proposed resolution

Since we are converting plugin definitions to PHP attributes it should be possible to use PHP constants instead of string literals. I think this will ease refactoring and improve DX. No need to rely on phpstorm-meta for auto-completion.

Example

#[FieldType(
  id: self::ID,
  label: new TM('Example'),
  default_widget: ExampleWidget::ID,
  default_formatter: ExampleFormatter::ID,
  list_class: ExampleItemList::class,
)]
final class ExampleItem extends FieldItemBase {
  
  public const string ID = 'example';  

}
$fields['example'] = BaseFieldDefinition::create(Example::ID)
  ->setLabel(t('Example'))
  ->setDisplayOptions('form', ['type' => ExampleWidget::ID])
  ->setDisplayOptions('view', ['type' => ExampleFormatter::ID]);
✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
PluginΒ  β†’

Last updated about 14 hours ago

Created by

πŸ‡·πŸ‡ΊRussia Chi

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

Comments & Activities

Production build 0.71.5 2024