Updated: Comment #N

Problem/Motivation

We're trying to get rid of all usages of global $conf and delete/rename it. #2167109: Remove Variable subsystem discovered that the DrupalKernel still uses it for something that should be a Setting, see things like PhpStorageFactory for an example.

In HEAD in order to use this functionality in settings.php you would have to do either:

global $conf;
$conf['container_service_providers']['MyClassName'] = 'Drupal\My\Namespace\MyClassName';

or just access $GLOBALS directly...

$GLOBALS['conf']['container_service_providers']['MyClassName'] = 'Drupal\My\Namespace\MyClassName';

This is because in Settings::initialize() we only set up 2 globals... global $config_directories, $config;. Because of this I think the functionality is basically broken.

Proposed resolution

Replace it with a call to Settings::getSingleton(), update code that does set this on demand.

We could add a BC-layer to Settings::initialise() and merge $GLOBALS['conf']['container_service_providers'] with the new setting.

Remaining tasks

Agree if we want a BC layer.
Commit

User interface changes

None

API changes

Remove $GLOBALS['conf']['container_service_providers']
Add $settings['container_service_providers']

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

In light of #2160705: settings.php setting names are inconsistent (and undocumented), I think we should cover both of these here:

$conf['container_service_providers'] → array map of "name" to FQCN
$conf['container_yamls'] → array of service yaml filepaths

If I may ask, why do we provide two ways to register custom services?

If we're going to keep that, could we at least shorten + simplify the names?

$settings['service_providers']['MyServiceProvider'] = 'Drupal\Yada\MyServiceProvider';
$settings['service_files'][] = $conf_path . '/services.yml';

Also, why do I need to manually specify the basename of a custom service provider class?

$ php -r "var_dump(basename('Drupal\Yada\MyServiceProvider'));"
string(17) "MyServiceProvider"

Long story short, I'd like to see more or less this:

$settings['service_providers'][] = 'Drupal\Yada\MyServiceProvider';
$settings['service_files'][] = $conf_path . '/services.yml';
alexpott’s picture

Status: Active » Needs review
FileSize
10.56 KB

So actually the $conf['container_yamls'] is already a setting.

$conf['container_service_providers'] not only is class names but can be full objects. Not sure why. However I think we can convert it to a setting and break the extremely undocumented API.

Status: Needs review » Needs work

The last submitted patch, 2: 2183323.2.patch, failed testing.

The last submitted patch, 2: 2183323.2.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
FileSize
1.3 KB
11.23 KB

Fixing installer.

Status: Needs review » Needs work

The last submitted patch, 5: 2183323.4.patch, failed testing.

The last submitted patch, 5: 2183323.4.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
FileSize
721 bytes
11.7 KB

Ah I see...

dawehner’s picture

+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -586,11 +586,9 @@ public function discoverServiceProviders() {
-    if (!empty($GLOBALS['conf']['container_service_providers'])) {
-      foreach ($GLOBALS['conf']['container_service_providers'] as $class) {
-        if ((is_string($class) && class_exists($class)) || (is_object($class) && ($class instanceof ServiceProviderInterface || $class instanceof ServiceModifierInterface))) {
-          $this->serviceProviderClasses['site'][] = $class;
-        }
+    foreach (Settings::get('container_service_providers', []) as $class) {
+      if ((is_string($class) && class_exists($class)) || (is_object($class) && ($class instanceof ServiceProviderInterface || $class instanceof ServiceModifierInterface))) {
+        $this->serviceProviderClasses['site'][] = $class;
       }
     }

So this means exising sites with stored $conf will break?

alexpott’s picture

@dawehner how are they setting $conf... if you just to $conf['blah'] in settings .php it is not enough. We already broke that. See Settings::initialise().

alexpott’s picture

Added a CR https://www.drupal.org/node/2568747

I think we should do this because having something around using D7's $GLOBALS['conf'] is super confusing.

dawehner’s picture

Category: Task » Bug report
Status: Needs review » Reviewed & tested by the community

@dawehner how are they setting $conf... if you just to $conf['blah'] in settings .php it is not enough. We already broke that. See Settings::initialise().

WOW, I wasn't aware of that

Berdir’s picture

@dawehner how are they setting $conf... if you just to $conf['blah'] in settings .php it is not enough. We already broke that. See Settings::initialise().

Easy, we even document how:

$GLOBALS['conf']['container_service_providers']['MyClassName'] = 'Drupal\My\Namespace\MyClassName';

Or..

global $conf;
$conf['container_service_providers']['MyClassName'] = 'Drupal\My\Namespace\MyClassName';

:)

Yes, weird and very non-obvious. But it works so this *is* a change.

OK with the rename, just wanted to point it out ;)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 8: 2183323.8.patch, failed testing.

alexpott’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
11.72 KB

Rerolled

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2183323-15.patch, failed testing.

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2183323-15.patch, failed testing.

Status: Needs work » Needs review

alexpott queued 15: 2183323-15.patch for re-testing.

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

Damn you pifr

alexpott’s picture

Issue summary: View changes
alexpott’s picture

Issue summary: View changes
alexpott’s picture

Issue summary: View changes

Discussed with @catch - we both feel that since you have to do global $conf or access $GLOBALS['conf'] directly providing a BC layer is not worth it.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 2183323-15.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
FileSize
11.71 KB

Rerolled

alexpott’s picture

tstoeckler’s picture

Discussed with @catch - we both feel that since you have to do global $conf or access $GLOBALS['conf'] directly providing a BC layer is not worth it.

Can you elaborate that? What will happen with sites currently using this feature?

alexpott’s picture

@tstoeckler they need to change. How are your sites using this feature?

Mile23’s picture

Version: 8.0.x-dev » 8.2.x-dev

Patch in #25 still applies to 8.1.x and 8.2.x.

Setting to 8.2.x and re-running the test.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

bircher’s picture

re-roll patch, many things have changed since this last applied, so fingers crossed!

bircher’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
858 bytes
13.76 KB

Small nit: there was still a $conf in the annotation.
This was RTBC, I just re-rolled it to 8.6 so, can still be RTBC in my opinion.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I'm not sure if I agree with myself on BC anymore. I think we should provide BC but deprecate the usage of the global.

  1. +++ b/core/globals.api.php
    @@ -42,18 +42,6 @@
    - * To define a site-specific service provider class, use code like this:
    - * @code
    - * $GLOBALS['conf']['container_service_providers']['MyClassName'] = 'Drupal\My\Namespace\MyClassName';
    - * @endcode
    - *
    

    We're telling people how to do it. So I now think we need a BC layer.

  2. +++ b/core/includes/install.core.inc
    @@ -137,7 +137,9 @@ function install_drupal($class_loader, $settings = []) {
    +   $settings = Settings::getAll();
    +   unset($settings['container_service_providers']['InstallerServiceProvider']);
    +   new Settings($settings);
    

    Wrong indentation.

bircher’s picture

Status: Needs work » Needs review
FileSize
14.96 KB
2.78 KB

I agree, we do need BC.
We use this in some cases for testing so it is definitely good to not break horribly.
I also moved the documentation part to settings.php as one would use it there.

Do we need to exercise the BC path in a test?

alexpott’s picture

@bircher yep and ideally we need to trigger a silenced deprecation notice too.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

neclimdul’s picture

  1. +++ b/core/includes/install.core.inc
    @@ -137,7 +137,9 @@ function install_drupal($class_loader, $settings = []) {
    +    new Settings($settings);
    
    +++ b/core/includes/install.inc
    @@ -610,10 +610,12 @@ function drupal_verify_profile($install_state) {
    +  new Settings($settings);
    
    +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
    @@ -332,12 +332,10 @@ private function bootKernel() {
    +    new Settings($settings);
    

    oof this pattern is terrible... but yeah that's right :(

  2. +++ b/core/includes/install.core.inc
    @@ -403,20 +405,22 @@ function install_begin_request($class_loader, &$install_state) {
    +  // Only allow dumping the container once the hash salt has been created.
    +  $environment = $install_state['base_system_verified'] ? 'prod' : 'install';
    +  // Only allow dumping the container once the hash salt has been created.
    +  $kernel = InstallerKernel::createFromRequest($request, $class_loader, $environment, (bool) Settings::get('hash_salt', FALSE));
    ...
    -  // Only allow dumping the container once the hash salt has been created.
    -  $kernel = InstallerKernel::createFromRequest($request, $class_loader, $environment, (bool) Settings::get('hash_salt', FALSE));
    

    "Only allow dumping the container once the hash salt has been created." is duplicated in the new code.

    Seems moving this has something to do with fixing the installer in #5 and #8 but its not clear to me how it does. Is there something we should document about why the code has to be before and how its fixing the dumping?

    Also we call Settings::get('hash_salt', FALSE)) and then immediately after call Settings::getAll(). Should we just be using the fetched settings or is this connected to all the Setting hacks we have going on somehow?

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

voleger’s picture

Status: Needs review » Needs work

Needs reroll

voleger’s picture

Issue tags: +Needs reroll
ravi.shankar’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
10.39 KB
8.65 KB

Added reroll of patch #37 on Drupal 9.5.x.

Status: Needs review » Needs work

The last submitted patch, 50: 2183323-50.patch, failed testing. View results

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.