DerivativeDiscoveryDecorator not supporting object definitions

Created on 21 May 2024, 26 days ago

Problem/Motivation

This started for me because I had duplicated plugin definitions in code but it may be a serious issue for someone and believe me, debugging it was a little nightmare.

Basically we have those new object oriented plugin definitions so a definition doesn't have to be an array anymore. Unfortunately core lacks full support of the feature: Drupal\Component\Plugin\Derivative\DeriverInterface::getDerivativeDefinitions and Drupal\Component\Plugin\Derivative\DeriverInterface::getDerivativeDefinition clearly say those should be arrays and not objects.
Objects are not supported at all by Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator, for example mergeDerivativeDefinition() that uses array_filter on derivatives.

The case of having to merge derivative definition with base plugin definition may be very rare since this hasn't surfaced yet (ok, my searching skills may not be good enough as well) but if anyone encounters it, the project is completely broken after introducing such config.

Encountered error for easier searching:

TypeError: array_filter(): Argument #1 ($array) must be of type array, Drupal\group\Plugin\Group\Relation\GroupRelationType given in /var/www/html/web/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php on line 241 #0 /var/www/html/web/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(241): array_filter(Object(Drupal\group\Plugin\Group\Relation\GroupRelationType))

Workaround: debug which plugins / derivatives may return identical IDs that core would want to merge.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
PluginΒ  β†’

Last updated about 18 hours ago

Created by

πŸ‡΅πŸ‡±Poland Graber

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

Comments & Activities

Production build 0.69.0 2024