diff --git a/core/core.services.yml b/core/core.services.yml index a83af34..e62047e 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -273,7 +273,7 @@ services: tags: - { name: event_subscriber } - { name: service_collector, tag: 'config.factory.override', call: addOverride } - arguments: ['@config.storage', '@event_dispatcher', '@config.typed'] + arguments: ['@config.storage', '@event_dispatcher', '@config.typed', '@settings'] config.importer_subscriber: class: Drupal\Core\Config\Importer\FinalMissingContentSubscriber tags: diff --git a/core/globals.api.php b/core/globals.api.php index 1487b19..b17c6fa 100644 --- a/core/globals.api.php +++ b/core/globals.api.php @@ -56,12 +56,20 @@ /** * Array of configuration overrides from the settings.php file. + * + * @internal + * Global configuration overrides should only be set in settings.php. Use + * \Drupal\Core\Site\Settings::getConfigOverride() to access data. */ global $config; /** * The location of file system directories used for site configuration data. * + * @internal + * Configuration directories should only be set in settings.php. Use + * config_get_config_directory() to access data. + * * @see drupal_install_config_directories() */ global $config_directories; diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index c56dfe8..22aa190 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\Cache; +use Drupal\Core\Site\Settings; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -73,11 +74,14 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface * An event dispatcher instance to use for configuration events. * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config * The typed configuration manager. + * @param \Drupal\Core\Site\Settings $settings + * (optional) The site settings. */ - public function __construct(StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config) { + public function __construct(StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config, Settings $settings = NULL) { $this->storage = $storage; $this->eventDispatcher = $event_dispatcher; $this->typedConfigManager = $typed_config; + $this->settings = $settings ?: Settings::getInstance(); } /** @@ -121,9 +125,7 @@ protected function doGet($name, $immutable = TRUE) { $config->setModuleOverride($overrides[$name]); } // Apply any settings.php overrides. - if (isset($GLOBALS['config'][$name])) { - $config->setSettingsOverride($GLOBALS['config'][$name]); - } + $config->setSettingsOverride($this->settings->getConfigOverride($name)); } foreach ($this->configFactoryOverrides as $override) { @@ -183,9 +185,7 @@ protected function doLoadMultiple(array $names, $immutable = TRUE) { if (isset($module_overrides[$name])) { $this->cache[$cache_key]->setModuleOverride($module_overrides[$name]); } - if (isset($GLOBALS['config'][$name])) { - $this->cache[$cache_key]->setSettingsOverride($GLOBALS['config'][$name]); - } + $this->cache[$cache_key]->setSettingsOverride($this->settings->getConfigOverride($name)); } $this->propagateConfigOverrideCacheability($cache_key, $name); diff --git a/core/lib/Drupal/Core/Site/Settings.php b/core/lib/Drupal/Core/Site/Settings.php index ee786db..93cf1b1 100644 --- a/core/lib/Drupal/Core/Site/Settings.php +++ b/core/lib/Drupal/Core/Site/Settings.php @@ -175,4 +175,15 @@ public static function getApcuPrefix($identifier, $root, $site_path = '') { return 'drupal.' . $identifier . '.' . \Drupal::VERSION . '.' . static::get('deployment_identifier') . '.' . Crypt::hashBase64($root . '/' . $site_path); } + /** + * Gets the configuration overrides set in settings.php. + * + * @return array + * An array configuration data. If no overrides are set then an empty array + * if returned. + */ + public static function getConfigOverride($config_name) { + return isset($GLOBALS['config'][$config_name]) ? $GLOBALS['config'][$config_name] : []; + } + }