Problem/Motivation
In #3112298: Replace REQUEST_TIME in classes with direct container access @alexpott tried to autowire a controller:
public function __construct(
protected ?TimeInterface $time = NULL
) {
TimeInterface is declared as an alias so this should work, but because the argument is nullable it did not actually work and the argument had to be explicitly autowired:
public function __construct(
#[Autowire(service: 'datetime.time')]
protected ?TimeInterface $time = NULL
) {
Steps to reproduce
Proposed resolution
Allow nullable types to be autowired the same way as non-nullable ones.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3410222
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:
- 3410222-10.2.x
changes, plain diff MR !6364
- 3410222-autowiring-does-not
changes, plain diff MR !5949
Comments
Comment #3
alexpottComment #5
mondrakeNice one, very useful
Comment #6
quietone commentedI'm triaging RTBC issues. I read the IS, the comments and the MR. I didn't find any unanswered questions or other work to do.
Leaving at RTBC.
Comment #7
longwaveCommitted da98f3b and pushed to 11.x. Thanks!
As a bug fix and given that autowiring was present in 10.2.x this is eligible for backport, but doesn't cherry-pick cleanly - if someone can backport the patch we can commit it there as well.
Comment #9
longwaveWhoops, forgot to push (thanks @alexpott), done now.
Comment #11
alexpottCreated https://git.drupalcode.org/project/drupal/-/merge_requests/6364 for the cherry pick - the core/modules/toolbar/src/Controller/ToolbarController.php changes were not necessary because that change was not in 10.2.x
Comment #13
longwaveCommitted 0b80bc5 and pushed to 10.2.x. Thanks!