Problem/Motivation

In PluginReferenceConfigurationFormTrait the $plugin_id can be NULL for an empty widget, this leads to a deprecation: E_DEPRECATED: Using null as an array offset is deprecated, use an empty string instead.

PluginReferenceConfigurationFormTrait:148 → \Drupal\Component\Plugin\Discovery\DiscoveryTrait::hasDefinition() → \Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait::getDefinition() → \Drupal\Component\Plugin\Discovery\DiscoveryTrait::doGetDefinition() — if (isset($definitions[$plugin_id])) {.

The main problem is that \Drupal\Component\Plugin\Discovery\DiscoveryInterface::hasDefinition() is documented to accept only a string, but the trait passes NULL, which triggers a PHP deprecation (before PHP 8.5, NULL was silently cast to an empty string). In environments where deprecations throw an exception (e.g. Whoops) this breaks the form with a 500 error.

Steps to reproduce

  1. Run Drupal on PHP 8.5 with deprecation reporting enabled (E_DEPRECATED in error_reporting).
  2. Add a content/config entity form that uses the plugin reference select or autocomplete widget.
  3. Open the "Add" form where the field is empty.

Proposed resolution

Do not call hasDefinition() when $plugin_id is NULL.

Remaining tasks

User interface changes

API changes

Data model changes

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:

Comments

niklan created an issue.