Problem

  1. 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

  1. Make DrupalKernel automatically consume a $conf_path/services.yml file, if available.

Comments

sun’s picture

Status: Active » Needs review
StatusFileSize
new7.56 KB
  1. Added (optional) inclusion of $conf_path/services.yml to DrupalKernel.
  2. Added test.
  3. Fixed service provider classes always override service.yml; site-specific overrides are not processed last.

Status: Needs review » Needs work

The last submitted patch, 1: site.services.1.patch, failed testing.

dawehner’s picture

  1. +++ b/core/lib/Drupal/Core/DrupalKernel.php
    @@ -138,6 +131,13 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
       /**
    +   * The list of the classnames of the service providers in this kernel.
    +   *
    +   * @var array
    +   */
    +  protected $serviceProviderClasses;
    +
    

    This is no longer true as you key by app as well. Can you elobarate here about the difference between app and site, please?

  2. +++ b/core/lib/Drupal/Core/DrupalKernel.php
    @@ -226,30 +228,30 @@ public function discoverServiceProviders() {
    +    if ($exists = file_exists($site_services_yml = conf_path() . '/services.yml')) {
    +      $this->serviceYamls['site'][] = $site_services_yml;
         }
    

    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?

  3. +++ b/core/modules/system/lib/Drupal/system/Tests/DrupalKernel/DrupalKernelSiteTest.php
    @@ -0,0 +1,50 @@
    +
    +  public static function getInfo() {
    +    return array(
    ...
    +  function testServicesYml() {
    

    nitpicks: @inheritdoc + public

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new9.13 KB
new3.52 KB
  1. Fixed DrupalKernel::$serviceProviders does not contain 'site' key if there are no site-specific service providers.
  2. Added/fixed phpDoc.
  3. Added small pointer for services.yml to settings.php @file phpDoc.
sun’s picture

StatusFileSize
new9.28 KB
new1.92 KB

Assert that swapping out (overriding) a core service works.

Status: Needs review » Needs work

The last submitted patch, 5: site.services.5.patch, failed testing.

The last submitted patch, 4: site.services.4.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new11.14 KB
new2.59 KB

Fixed ModifyServiceDefinitionsPass.

sun’s picture

Great. 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.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Yeah that patch is looking fine.

sun’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 8: site.services.8.patch, failed testing.

sun’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new11.13 KB

Merged 8.x.

sun’s picture

This issue is blocking the related issues from moving forward.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: site.services.13.patch, failed testing.

sun’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new11.18 KB
new834 bytes
sun’s picture

Would 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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: site.services.16.patch, failed testing.

sun’s picture

16: site.services.16.patch queued for re-testing.

sun’s picture

Status: Needs work » Reviewed & tested by the community
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

  • Commit c5c075d on 8.x by catch:
    Issue #2241633 by sun: Simplify site-specific service overrides.
    
moshe weitzman’s picture

How about an example.services.yml that folks can use to learn syntax and hint at the possibilities?

alexpott’s picture

chx’s picture

Status: Fixed » Active

I 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 ?

catch’s picture

Status: Active » Postponed

Reverted.

A) how did a new feature made into core at this stage?

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).

C) How could this possibly get in before #2183323: Replace $GLOBALS['conf']['container_service_providers'] in DrupalKernel with Settings

I didn't think there was much of a conflict. But let's postpone it.

  • Commit ecf2fa7 on 8.x by catch:
    Revert "Issue #2241633 by sun: Simplify site-specific service overrides...

  • Commit 8723cb9 on 8.x by catch:
    Revert "Revert "Issue #2241633 by sun: Simplify site-specific service...
catch’s picture

Status: Postponed » Active

Can't revert that when #2266547: TestKernel is not adding its service provider correctly. has been committed already. Not enough tea yet today.

chx’s picture

Status: Active » Fixed

:( 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.