Problem/Motivation

final class ApiComponentsController implements ContainerInjectionInterface {

  use AutowireTrait;

  public function __construct(
    private readonly RendererInterface $renderer,
    #[Autowire(param: 'renderer.config')]
    private readonly array $rendererConfig,
    private readonly AccountSwitcherInterface $accountSwitcher,
  ) {}

This works if the class is autowired as a service - autowiring in the container allows parameters - but not if it is invoked directly as a controller, because AutowireTrait assumes the attribute is only used for service names.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3490300

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

longwave created an issue. See original summary.

longwave’s picture

Status: Active » Needs work
Issue tags: +Needs tests

wim leers credited catch.

wim leers’s picture

Per @catch's comments #17 and #19 on #3490300, this is now pretty much a hard blocker.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

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

gabesullice’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
gabesullice’s picture

Title: Allow AutowireTrait to wire parameters » Allow AutowiredInstanceTrait to wire container parameters
dcam’s picture

Status: Needs review » Needs work

There's some duplication at the very least. They both modify AutowiredInstanceTrait in the same place, so one of them is going to have to be rebased. The other issue is RTBC and this one needs a rebase. I'm going to set this to Needs Work because of that, but maybe we need to wait on this until the other is committed.

gabesullice’s picture

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.