Problem/Motivation
Drupal has restricted service IDs/names to be lowercased since before Drupal 8: #2498293: Only allow lowercase service and parameter names.
Since then, Symfony has added "autowiring" of services. We're working to adopt that in Drupal: #3295751: Autowire core services that do not require explicit configuration, #3049525: Enable service autowiring by adding interface aliases to core service definitions, #3228629: [meta] Bring dependency injection more in line with upstream Symfony component.
But … that restriction from 2015 prevents this adoption.
Worse, that restriction is implemented inconsistently! Quoting @Wim Leers from #2503567-51: Only allow lowercase service and parameter names [part 2]:
This is showing up explicitly in #3314137: Make Automatic Updates Drupal 10-compatible since #3284422: [META] Symfony 6.2 compatibility due to changes in Symfony 6.2's
FileLoader
— see #3314137-27: Make Automatic Updates Drupal 10-compatible and #3314137-28: Make Automatic Updates Drupal 10-compatible for details. In #3314137-29: Make Automatic Updates Drupal 10-compatible I discovered that even Drupal core's existing autowiring test technically violatespublic function register($id, $class = NULL): Definition { if (strtolower($id) !== $id) { throw new \InvalidArgumentException("Service ID names must be lowercase: $id"); }
… by
somehowbypassing it thanks to::setDefinition()
, which doesn't have that same check:
😬
So I agree with @longwave in #49. Closing this. See y'all in #3049525: Enable service autowiring by adding interface aliases to core service definitions.
The only reason this hasn't come up in the limited autowiring support we have today is because that has used \Drupal\Core\DependencyInjection\ContainerBuilder::setAlias()
, which … does not have this restriction — an oversight from #2498293: Only allow lowercase service and parameter names 😅
Proposed resolution
Allow uppercase service IDs.
Remaining tasks
TBD
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
TBD
Comment | File | Size | Author |
---|---|---|---|
#8 | 3320315-8.patch | 2.36 KB | Wim Leers |
#8 | interdiff.txt | 1.14 KB | Wim Leers |
#6 | 3320315-5.patch | 3.2 KB | Anchal_gupta |
#6 | interdiff-3320315-2_5.txt | 737 bytes | Anchal_gupta |
#2 | 3320315-2.patch | 2.98 KB | Wim Leers |
Comments
Comment #2
Wim LeersLet's see how this does.
Comment #3
Wim LeersComment #4
alexpottRemoving this is not correct. This is skipping the parent and calling the parent of parent....
Comment #5
longwaveWe should write a short change record and also update https://www.drupal.org/node/2498887 to note that it is now obsolete.
Comment #6
Anchal_gupta CreditAttribution: Anchal_gupta at Srijan | A Material+ Company for Drupal India Association commentedFixed CS error. Please review it
Comment #7
alexpottAs per #4 - fixing the CS error is not enough... in fact we need to add the use statement back in and only remove the case check...
The code should like this:
Comment #8
Wim Leers#4: ah, so that's why it didn't use
parent::
! 😄Comment #9
Wim LeersComment #10
Wim LeersWithout this, I had to add this insane (and unmaintainable) work-around to make https://www.drupal.org/project/automatic_updates work on Drupal 10/Symfony 6.2: https://git.drupalcode.org/project/automatic_updates/-/merge_requests/52...
Also, yay, #8 is green! I marked it — to assert we can now add uppercase service IDs. But … is that really worth testing? 🤔
Comment #11
alexpottI don't think we should add tests - we're removing the code and soon enough we'll have uppercase services I guess.
Comment #12
Wim Leers#11: 👍
#5:
Comment #13
longwaveLooks good to me. I fixed one of the links in the change record but otherwise everything is great, we are only removing code here :)
Comment #14
alexpottCommitted and pushed a5f4685c6a to 10.1.x and 95e742555b to 10.0.x and 23a9ff75be to 9.5.x. Thanks!
Backported this to 9.5.x to make making D9/10 modules easier.
Comment #15
Wim LeersWoah!!! That was incredibly fast :D Very grateful for that, makes #3314137-33: Make Automatic Updates Drupal 10-compatible far less of a dystopian satirical nightmare 😆