Problem/Motivation
Autowiring is the future!
create() functions hard code dependencies into implementation code, and make higher levels of PHPStan unhappy.
Autowiring is already supported in many places, and support for PlugIns is coming in 11.3.
When complete, autowiring should make our codebase cleaner, easier to follow, and more maintainable.
Steps to reproduce
N/A
Proposed resolution
- Look at changing the services.yml to use autowiring for as many services as possible.
ControllerBase already uses AutowireTrait, which means that most controllers can just remove the create() function with no other changes required.
- Any classes that implement
ContainerInjectionInterface can support autowiring by using the AutowireTrait. This includes forms.
- Support for autowiring in Plugins is being added in 11.3, with 11.3.0-alpha1 released on 6th November, and a stable release targeted for December. We should consider whether to increase
core_version_requirement to 11.3 to allow autowiring of plugins and whether to increase our minimum Drupal version to utilise it.
- There have been some concerns about the performance of autowiring due to the use of reflection, but 11.3 moves some of this to the discovery phase, reducing the burden at runtime
Remaining tasks
- Discuss whether to move to autowiring, and the timeline for doing so.
- Consider whether to increase
core_version_reequirement, and what stage in the 11.3 cycle to do so.
- Implement autowiring wherever possible.
- Implement autowiring.
- Be happy.
User interface changes
None
API changes
None
Data model changes
None
Comments
Comment #2
jdleonardThis seems sensible.
If the known performance issues are mostly mitigated with the release of Drupal 11.3, and with its release expected in 2025, I'm in favor of this change being made now so long as we don't increase the
core_version_requirement.For those for whom the performance implications are significant, they can upgrade to Drupal 11.3. However, I'm against requiring all potential users of CRM with existing Drupal 11.1 or 11.2 sites to upgrade their sites just to use CRM. We should keep the barrier to adopting CRM as low as possible.
I'd propose that a follow up issue be created to do this for plugins, postponed on
core_version_requirementbecoming >= 11.3.Comment #3
lostcarpark commentedDrupal 11.3 is expected in December, when 11.1 will become unsupported, so while keeping our core_version_requirement on 11.1 is fine, people should upgrade to at least 11.2 if possible.
We could consider increasing our minimum to 11.3 either in mid-2026 when 11.4 is released and 11.2 unsupported, or in December 2026 when 12 is expected to release, and the supported versions of 11 will be 11.4 and 11.5 (and all versions of D10 will be unsupported).
Comment #4
jdleonardSounds good.
@lostcarpark, do you want to proceed with this task (excepting plugins)? If so, please assign!
Comment #5
jdleonardComment #7
jdleonardI experimented with Claude Code for this and it worked quite well. Quite a bit of boilerplate reduction, reducing surface area for coding style issues, etc.
Once side effect of the related class function parameter promotion is a mix of camelCase and snake_case for class function parameters. This seems like a worthwhile tradeoff for the time being.
Comment #8
svendecabooterHad a look at the changes and they look good to me.
Using autowiring makes the code less verbose and easier to read, so +1 from me.
Comment #9
svendecabooterComment #12
bluegeek9 commented