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
- Run Drupal on PHP 8.5 with deprecation reporting enabled (
E_DEPRECATEDinerror_reporting). - Add a content/config entity form that uses the plugin reference select or autocomplete widget.
- 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
Issue fork pluginreference-3630827
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