Problem/Motivation

The module has several areas that need modernization to align with current Drupal 10.3+ / 11 best practices:

  • Hook implementations live as procedural code in .module instead of using the OOP hook pattern.
  • The test plugin (DummyType) uses the deprecated @Annotation discovery instead of PHP attributes.
  • The formatter outputs plugin labels with #markup, which does not escape user-controlled text, posing a potential XSS risk.
  • PHPStan was running at level 1; several loose types (@return mixed, loose equality ==, static:: calls on instance methods) would be caught at higher levels.
  • The storageSettingsSummary() displays the raw machine name of the plugin type instead of its human-readable label.
  • The widget's supportsConfiguration() does not guard against an empty definitions array, causing a potential error.
  • Attribute strings use double quotes instead of single quotes (minor style inconsistency).
  • The module requires ^10 but realistically depends on APIs available from 10.3+.

Proposed resolution

1. OOP hook migration

  • Add plugin_configuration_field.services.yml with the PluginConfigurationFieldHooks service.
  • Move hook_field_widget_info_alter() and hook_field_formatter_info_alter() logic into that class.
  • Keep thin procedural wrappers in .module for backward compatibility with Drupal versions without #[Hook] auto-discovery.

2. Annotation to PHP attribute

  • Replace the @DummyType annotation class with a DummyType PHP attribute in the test module.
  • Update BasicDummyType to use the #[DummyType] attribute.
  • Delete the now-unused Annotation/DummyType.php.

3. Stricter types and code quality (PHPStan level 5)

  • Raise PHPStan level from 1 to 5.
  • Fix loose equality (== to ===) in isEmpty().
  • Change getPluginManager() from static to instance method.
  • Add proper @return type to the deriver's getEvent().
  • Add static return type to create().
  • Replace get_class($this) with static::class.
  • Normalize attribute strings to single quotes.
  • Add type annotations (@var) in the widget for field items.

4. UX: human-readable label in storage settings summary

  • storageSettingsSummary() now dispatches the plugin types event to resolve the label instead of showing the machine name.

5. Widget empty-definitions guard

  • supportsConfiguration() returns FALSE early when definitions array is empty.

6. Core version requirement bump

  • core_version_requirement changed from ^10 to ^10.3 || ^11.

7. API documentation

  • Add plugin_configuration_field.api.php documenting the types event hook.

8. Expanded test coverage

  • New kernel tests: PluginConfigurationFieldElementTest, PluginConfigurationFieldFormatterTest.
  • New functional test: PluginConfigurationFieldWidgetTest.
  • New unit test: PluginConfigurationFieldTypesEventTest.
  • Additional assertions in existing kernel test: testIsEmpty(), testStorageSettingsSummaryShowsLabel(), testSetValueDefaultsConfiguration().

9. README rewrite

  • Complete rewrite with architecture overview, registration guide, usage examples, and submodule documentation.

User interface changes

Storage settings summary now shows the human-readable plugin type label (e.g., "Reference type: Basic dummy type") instead of the machine name.

API changes

  • getPluginManager() changed from protected static to protected (instance method). Subclasses calling static::getPluginManager() must update to $this->getPluginManager().
  • New plugin_configuration_field.services.yml registers the OOP hooks service.
  • New plugin_configuration_field.api.php documents the types event hook.

Data model changes

None. The field schema (two columns: target_plugin_id and target_plugin_configuration) is unchanged.

Command icon 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:

  • 1.x Comparechanges, plain diff MR !2

Comments

facine created an issue. See original summary.

  • facine committed 412aef03 on 1.x
    feat: #3579691 Modernize codebase: OOP hooks, PHP attributes, stricter...
facine’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • facine committed 79007013 on 1.x
    feat: #3579691 Modernize codebase: OOP hooks, PHP attributes, stricter...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.