- Issue created by @donquixote
In Drupal, all the service definitions I find in *.services.yml files have explicit complete argument lists, like so:
services:
[..]
system.manager:
class: Drupal\system\SystemManager
arguments: ['@module_handler', '@request_stack', '@menu.link_tree', '@menu.active_trail']
The symfony dependency injection component also allows an advanced syntax, that is useful in combination with autowiring.
https://symfony.com/doc/current/service_container.html#choose-a-specific...
This allows to specify only _some_ of the arguments, where autowiring does not work.
A preview of this in Drupal can already be seen here:
π
Use autowiring for core modules and services
Needs work
https://git.drupalcode.org/project/drupal/-/merge_requests/2508/diffs
services:
block_content.uuid_lookup:
class: \Drupal\block_content\BlockContentUuidLookup
autowire: true
arguments:
$cache: '@cache.bootstrap'
While that issue is for Drupal 10, I found that the autowire already works for Drupal 9.5.
This can be useful for custom or contrib modules that already want to go ahead and use autowired services.
However:
Use Drupal 9.5 or up.
Create custom module with autowired services and advanced arguments syntax.
Open in PhpStorm -> inspection warning.
Rebuild the container -> no problem, seems to work just fine.
Add a test case to confirm that arguments binding already works.
Backport to 9.5.x.
Make a PR at schemastore, or ship our own schema for services.yml that IDEs like PhpStorm can find and understand.
none
none
none
The Drupal dependency injection system supports binding arguments by name or type as documented in https://symfony.com/doc/current/service_container.html#choose-a-specific....
This already worked before, but now it is official.
We should also support the 'bind' key in '_defaults', and "Binding arguments by Name or Type"
https://symfony.com/doc/current/service_container.html#binding-arguments....
See [3295542-3]
Active
9.5
Last updated