Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem
-
To override services (definitions) on a specific site, you need to set a global (!) variable in
settings.php
to this:$GLOBALS['conf']['container_yamls'][] = $conf_path . '/services.yml';
Proposed solution
-
Make
DrupalKernel
automatically consume a$conf_path/services.yml
file, if available.
Comment | File | Size | Author |
---|---|---|---|
#16 | interdiff.txt | 834 bytes | sun |
#16 | site.services.16.patch | 11.18 KB | sun |
#13 | site.services.13.patch | 11.13 KB | sun |
#8 | interdiff.txt | 2.59 KB | sun |
#8 | site.services.8.patch | 11.14 KB | sun |
Comments
Comment #1
sunComment #3
dawehnerThis is no longer true as you key by app as well. Can you elobarate here about the difference between app and site, please?
Do we hae a follow up to include also one for enviroment specific overrides? Can we get some documentation for the overrides into settings.php?
nitpicks: @inheritdoc + public
Comment #4
sunComment #5
sunAssert that swapping out (overriding) a core service works.
Comment #8
sunFixed ModifyServiceDefinitionsPass.
Comment #9
sunGreat. I did not expect to run into so many issues with this otherwise simple change, but I'm happy with this patch now and the functional test confirms that it works as expected.
That said, the overall code and logic in
DrupalKernel
is in dire need of clean-up as it took me quite a while to understand the call chains, but I don't want to touch that here, since out of scope.Comment #10
dawehnerYeah that patch is looking fine.
Comment #11
sunCreated follow-up #2244807: Replace $GLOBALS['conf']['container_yamls'] with optional $conf_path/services.$env.yml file
Comment #13
sunMerged 8.x.
Comment #14
sunThis issue is blocking the related issues from moving forward.
Comment #16
sunUpdated for #2252967: rebuildContainer() is not limited to web tests (WebTestBase)
Comment #17
sunWould be great to move forward here... This is a base building block that allows us to rethink what makes sense in settings.php and what doesn't.
Comment #19
sun16: site.services.16.patch queued for re-testing.
Comment #20
sunRandom test failure: #2257539: Random fail: InvalidArgumentException: "Unknown theme: bartik." in Drupal\config\Tests\ConfigImportUITest
Comment #21
catchCommitted/pushed to 8.x, thanks!
Comment #23
moshe weitzman CreditAttribution: moshe weitzman commentedHow about an example.services.yml that folks can use to learn syntax and hint at the possibilities?
Comment #24
alexpottThis broke CLI use of run-tests.sh see #2266547: TestKernel is not adding its service provider correctly.
Comment #25
chx CreditAttribution: chx commentedI no longer understand core process.
A) how did a new feature made into core at this stage?
B) how did this made in when these particular site overrides don't work with tests despite https://drupal.org/node/2229011#comment-8645239 predates the last patch (by a month) written by the author of this patch -- that comment says, if you override in settings.php then the overrides from site specific settings.php should persist into the tests. But, apparently not YAML ones? What?
C) How could this possibly get in before #2183323: Replace $GLOBALS['conf']['container_service_providers'] in DrupalKernel with Settings ?
Comment #26
catchReverted.
It's significantly harder to override implementations in settings.php than it was in 7.x, so simplifying that now isn't really a feature. Also I've been very clear on several occasions that I think 'feature freeze' is a pointless and counterproductive approach to the release cycle (although that doesn't mean trying to land massive new modules all the time either).
I didn't think there was much of a conflict. But let's postpone it.
Comment #29
catchCan't revert that when #2266547: TestKernel is not adding its service provider correctly. has been committed already. Not enough tea yet today.
Comment #30
chx CreditAttribution: chx commented:( So I guess then B) at least needs to be fixed: the override yaml needs to be copied over for testing. tstoeckler says that could be done in #2229011: Tests are no longer modifiable so let's just do that.