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
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 #2
dpiComment #3
nexusnovaz commentedI'll take a look at this
Comment #5
nexusnovaz commentedCopied over the text and made sure coding standards/ci passed!
Comment #6
smustgrave commentedMRs 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!
Comment #7
rduterteThe 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.
Comment #8
awset commentedI am working on it as part of DrupalCon Nara Contrib day 2025.
Comment #10
awset commentedraised a new PR against 11.x, most of the code changes made by previous contributor @nexusnovaz
Comment #11
rduterteComment #12
rduterteHi, 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.
Comment #13
rduterteComment #14
godotislateDocs for the trait method match the interface. lgtm
Comment #15
longwaveBackported 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!