Problem/Motivation
Since Drupal 11.4.0, DeriverInterface::getDerivativeDefinitions() accepts array|PluginDefinitionInterface as the parameter type (#3587110).
In the admin_toolbar_tools module, ExtraLinks::getDerivativeDefinitions() overrides the inherited PHPDoc and declares the parameter type as array<mixed>. This matched the parent definition prior to Drupal 11.4.0, but is no longer compatible with the parent signature starting with Drupal 11.4.0.
This causes issues for static analysis tools such as PHPStan whenever a class extends ExtraLinks and uses {@inheritdoc}.
Proposed resolution
- Update the PHPDoc of
ExtraLinks::getDerivativeDefinitions()to use@param array<mixed>|\Drupal\Component\Plugin\Definition\PluginDefinitionInterface $base_plugin_definition. - Keep the explicit
@paramand@return array<mixed>after{@inheritdoc}: with only{@inheritdoc}, PHPStan reportsmissingType.iterableValue, since the inherited types arearraywithout a value type.
An early return when $base_plugin_definition is not an array was considered but is not needed: ExtraLinks is only used as the deriver of a YAML menu link, and the YAML discovery always passes the base definition as an array. The core_version_requirement does not need to change either.
Remaining tasks
None.
User interface changes
None.
API changes
None: only the documentation of the method changes, not its signature or behavior.
Data model changes
None.
Issue fork admin_toolbar-3611568
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
johnatas commentedComment #5
liam morlandSince it has
@inheritdoc, it seems to me it shouldn't have@paramor@return. It should be possible to fix this without changingcore_version_requirement. Probably more needs to be done to be compatible with$base_plugin_definitionnot being an array.Comment #6
johnatas commentedIndeed, that makes more sense. I've just pushed a new commit that reverts the
core_version_requirementchanges and keeps only the@inheritdocand theif.Setting this back to Needs work to better handle the case where
$base_plugin_definitionis not an arrayComment #8
dydave commentedMerged, thanks a lot @johnatas for the report and the merge request, and @liam morland for the review! 🙏
Following Liam's comment at #5, the final change is limited to the PHPDoc of
ExtraLinks::getDerivativeDefinitions(): the@paramnow matches the parent (array<mixed>|\Drupal\Component\Plugin\Definition\PluginDefinitionInterface), with no change in the behavior, the signature or thecore_version_requirement.The explicit
@paramand@returnare kept after{@inheritdoc}, since PHPStan reportsmissingType.iterableValueotherwise (the inherited types arearraywithout a value type). The early return for a non-array base definition was not needed:ExtraLinksis only used as the deriver of a YAML menu link, so it always receives an array, and PHPStan passes without it.I updated the issue summary to the final resolution. The pipeline is green. 🟢