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 @param and @return array<mixed> after {@inheritdoc}: with only {@inheritdoc}, PHPStan reports missingType.iterableValue, since the inherited types are array without 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.

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

johnatas created an issue. See original summary.

johnatas’s picture

Status: Active » Needs review

dydave made their first commit to this issue’s fork.

liam morland’s picture

Since it has @inheritdoc, it seems to me it shouldn't have @param or @return. It should be possible to fix this without changing core_version_requirement. Probably more needs to be done to be compatible with $base_plugin_definition not being an array.

johnatas’s picture

Status: Needs review » Needs work

Indeed, that makes more sense. I've just pushed a new commit that reverts the core_version_requirement changes and keeps only the @inheritdoc and the if.

Setting this back to Needs work to better handle the case where $base_plugin_definition is not an array

  • dydave committed ed58c6b2 on 3.x authored by johnatas
    Issue #3611568 by johnatas, dydave, liam morland: Updated the...
dydave’s picture

Title: ExtraLinks::getDerivativeDefinitions() signature incompatible with DeriverInterface after Drupal 11.4.0 » ExtraLinks::getDerivativeDefinitions() docblock incompatible with DeriverInterface after Drupal 11.4.0
Issue summary: View changes
Status: Needs work » Fixed

Merged, 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 @param now matches the parent (array<mixed>|\Drupal\Component\Plugin\Definition\PluginDefinitionInterface), with no change in the behavior, the signature or the core_version_requirement.

The explicit @param and @return are kept after {@inheritdoc}, since PHPStan reports missingType.iterableValue otherwise (the inherited types are array without a value type). The early return for a non-array base definition was not needed: ExtraLinks is 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. 🟢

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.

Status: Fixed » Closed (fixed)

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