Summary
Convert deprecated @FieldWidget annotations to PHP 8 #[FieldWidget] attributes for Drupal 11 compatibility. Annotation-based plugin discovery is removed in Drupal 11, so the widgets are not discovered
at runtime despite the info.yml declaring ^11 support.
Changes required
- src/Plugin/Field/FieldWidget/SelectStringTextfieldWidget.php — Convert
@FieldWidgetannotation to#[FieldWidget]attribute - src/Plugin/Field/FieldWidget/SelectStringTextareaWidget.php — Convert
@FieldWidgetannotation to#[FieldWidget]attribute - src/Plugin/Field/FieldWidget/SelectFormattedTextfieldWidget.php — Convert
@FieldWidgetannotation to#[FieldWidget]attribute - src/Plugin/Field/FieldWidget/SelectFormattedTextareaWidget.php — Convert
@FieldWidgetannotation to#[FieldWidget]attribute - src/WidgetHelper.php — Replace
list($key, $value)with[$key, $value]array destructuring (minor cleanup)
All four widget files need:
- Add
use Drupal\Core\Field\Attribute\FieldWidget; - Add
use Drupal\Core\StringTranslation\TranslatableMarkup; - Replace
@FieldWidget(...)docblock with#[FieldWidget(...)]attribute - Replace
@Translation("...")withnew TranslatableMarkup('...')
Safe for all supported versions — attribute discovery works in Drupal 10.2+, and core_version_requirement already requires ^10.3.
Issue fork select_text_value-3582703
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
andyg5000Comment #5
mably commentedMerged. Thanks @andyg5000!