Problem/Motivation

Since \Drupal\Core\Plugin\PluginBase added a `create` method, downstream code utilising high level PHPStan is breaking on lack of typing.

Steps to reproduce

I have a plugin that extends \Drupal\Core\Layout\LayoutDefault. My plugin also uses ContainerFactoryPluginInterface.

ContainerFactoryPluginInterface::create has more typing for its $plugin_id parameter.

Now that my pipeline run against core HEAD, the new PluginBase::create takes effect, and shows the PHPStan error:

------ ---------------------------------------------------------------------
35 Parameter #3 $plugin_id (string) of method
MyCustomPlugin::create()
should be contravariant with parameter $plugin_id (mixed) of method
Drupal\Core\Plugin\PluginBase::create()
🪪 method.childParameterType

Proposed resolution

Add the same type information to match the existing ContainerFactoryPluginInterface::create by copying the entire @param section to PluginBase::create. Critically, the `string` for $plugin_id` is added.

Remaining tasks

Implement.

Tests are not required for this change.

This is a documentation only change.

We cannot yet test this/prevent regressions in core because core runs at a low stan version, though there are rumblings on how to get around it (mglaman?)

I want to remind the readers of this issue that core itself does not need to run phpstan level 1000 in order for downstream projects, contrib etc, to run a higher version than core.

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

None

Issue fork drupal-3554909

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

dpi created an issue. See original summary.

dpi’s picture

Issue summary: View changes
nexusnovaz’s picture

Assigned: Unassigned » nexusnovaz

I'll take a look at this

nexusnovaz’s picture

Assigned: nexusnovaz » Unassigned
Status: Active » Needs review

Copied over the text and made sure coding standards/ci passed!

smustgrave’s picture

Version: 11.3.x-dev » 11.x-dev
Status: Needs review » Needs work

MRs need to be against 11.x please

If you are another contributor eager to jump in, please allow the previous poster(s) at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!

rduterte’s picture

The Drupal Contribution Mentoring team is triaging issues for DrupalCon Nara 2025, and we are reserving this issue for Mentored Contribution during the event.

After November 19, this issue returns to being open to all. Thanks!

I performed Novice Triage on this issue.
I'm leaving the Novice tag because the work appears to be limited to adjusting the changes against the 11.x (or 11.x-dev) branch. No additional complexity seems required at this stage.

awset’s picture

I am working on it as part of DrupalCon Nara Contrib day 2025.

awset’s picture

raised a new PR against 11.x, most of the code changes made by previous contributor @nexusnovaz

rduterte’s picture

Issue tags: +Nara2025
rduterte’s picture

Hi, We've decided to create new MR due to we don't have permission to changed the target branch and we want to allow the new contributor to understand and follow the drupal flow for creating MR's. We will be updating the status to Needs Review.

rduterte’s picture

Status: Needs work » Needs review
godotislate’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Documentation

Docs for the trait method match the interface. lgtm

longwave’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Backported to 11.3.x as an eligible documentation fix. This feature wasn't in 10.6.x so no need to go back there.

Special thanks to the new contributors who worked on this issue in Nara!

Committed and pushed d9143d1bcb5 to 11.x and 35860d3ff13 to 11.3.x. Thanks!

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.

  • longwave committed 35860d3f on 11.3.x
    docs: #3554909 Narrowed typing regression for plugins
    
    By: dpi
    By:...

  • longwave committed d9143d1b on 11.x
    docs: #3554909 Narrowed typing regression for plugins
    
    By: dpi
    By:...

Status: Fixed » Closed (fixed)

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