diff --git a/core/core.services.yml b/core/core.services.yml index f7adc38..7cad914 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -589,7 +589,7 @@ services: arguments: ['@module_handler'] date: class: Drupal\Core\Datetime\Date - arguments: ['@entity.manager', '@language_manager', '@string_translation'] + arguments: ['@entity.manager', '@language_manager', '@string_translation', '@config.factory'] feed.bridge.reader: class: Drupal\Component\Bridge\ZfExtensionManagerSfContainer calls: diff --git a/core/includes/config.inc b/core/includes/config.inc index 64fb6a5..8a1aab5 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -17,35 +17,6 @@ */ /** - * Disable overrides on the configuration factory. - */ -function config_factory_disable_overrides() { - Drupal::service('config.factory')->disableOverrides(); -} - -/** - * Enable overrides on the configuration factory. - */ -function config_factory_enable_overrides() { - Drupal::service('config.factory')->enableOverrides(); -} - -/** - * Sets the language on the configuration object factory. - * - * @param Drupal\Core\Language\Language $language - * The language that config objects should have injected in to them. - * - * @return Drupal\Core\Language\Language $language - * The language object that was previously set in the config factory. - */ -function config_factory_set_language(Language $language = NULL) { - $current_language = Drupal::service('config.factory')->getLanguage(); - Drupal::service('config.factory')->setLanguage($language); - return $current_language; -} - -/** * Installs the default configuration of a given extension. * * When an extension is installed, it searches all the default configuration @@ -174,26 +145,6 @@ function config($name) { } /** - * Return a list of all config entity types provided by a module. - * - * @param string $module - * The name of the module possibly providing config entities. - * - * @return array - * An associative array containing the entity info for any config entities - * provided by the requested module, keyed by the entity type. - */ -function config_get_module_config_entities($module) { - // While this is a lot of work to generate, it's not worth static caching - // since this function is only called at install/uninstall, and only - // once per module. - $info = entity_get_info(); - return array_filter($info, function($entity_info) use ($module) { - return ($entity_info['module'] == $module) && is_subclass_of($entity_info['class'], 'Drupal\Core\Config\Entity\ConfigEntityInterface'); - }); -} - -/** * Returns the entity type of a configuration object. * * @param string $name diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 7d7362d..b0a14cb 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -2563,7 +2563,7 @@ function menu_router_rebuild() { function menu_router_build($save = FALSE) { // Ensure that all configuration used to build the menu items are loaded // without overrides. - config_factory_disable_overrides(); + \Drupal::configFactory()->disableOverrides(); // We need to manually call each module so that we can know which module // a given item came from. $callbacks = array(); @@ -2579,7 +2579,7 @@ function menu_router_build($save = FALSE) { // Alter the menu as defined in modules, keys are like user/%user. drupal_alter('menu', $callbacks); // Re-enable configuration overrides. - config_factory_enable_overrides(); + \Drupal::configFactory()->enableOverrides(); foreach ($callbacks as $path => $router_item) { // If the menu item is a default local task and incorrectly references a // route, remove it. diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index befb906..0be51e1 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -128,23 +128,6 @@ public function get($name) { } /** - * Returns a language overrides for a given configuration object. - * - * @param string $name - * The name of the configuration object to construct. - * - * @return \Drupal\Core\Config\Config - * A configuration object. - */ - public function getLanguageOverrides($name) { - $language_name = $this->getLanguageConfigName($name); - if ($language_name && $this->storage->exists($language_name)) { - return $this->storage->read($language_name); - } - return FALSE; - } - - /** * Returns a list of configuration objects for a given names. * * This will pre-load all requested configuration objects does not create @@ -160,13 +143,6 @@ public function loadMultiple(array $names) { global $conf; $list = array(); - if (!$this->useOverrides) { - foreach ($this->storage->readMultiple($names) as $name => $data) { - $list[$name] = new Config($name, $this->storage, $this->eventDispatcher, $this->typedConfigManager, $this->language); - $list[$name]->initWithData($data); - } - return $list; - } foreach ($names as $key => $name) { // @todo: Deleted configuration stays in $this->cache, only return @@ -180,28 +156,40 @@ public function loadMultiple(array $names) { // Pre-load remaining configuration files. if (!empty($names)) { - // In order to make just one call to storage, add in language names. - // Keep track of them separately, so we can get language override data - // returned from storage and set it on new Config objects. - $language_names = $this->getLanguageConfigNames($names); - $storage_data = $this->storage->readMultiple(array_merge($names, array_values($language_names))); - $moduleOverrides = $this->loadModuleOverrides($names); + if ($this->useOverrides) { + // In order to make just one call to storage, add in language names. + // Keep track of them separately, so we can get language override data + // returned from storage and set it on new Config objects. + $language_names = $this->getLanguageConfigNames($names); + $storage_data = $this->storage->readMultiple(array_merge($names, array_values($language_names))); + $moduleOverrides = $this->loadModuleOverrides($names); + } + else { + $language_names = array(); + $moduleOverrides = array(); + $storage_data = $this->storage->readMultiple($names); + } + foreach ($storage_data as $name => $data) { if (in_array($name, $language_names)) { + // Language override configuration is not regular configuration and + // therefore not cached or overridden. continue; } $cache_key = $this->getCacheKey($name); $this->cache[$cache_key] = new Config($name, $this->storage, $this->eventDispatcher, $this->typedConfigManager, $this->language); $this->cache[$cache_key]->initWithData($data); - if (isset($language_names[$name]) && isset($storage_data[$language_names[$name]])) { - $this->cache[$cache_key]->setLanguageOverride($storage_data[$language_names[$name]]); - } - if (isset($moduleOverrides[$name])) { - $this->cache[$cache_key]->setModuleOverride($moduleOverrides[$name]); - } - if (isset($conf[$name])) { - $this->cache[$cache_key]->setSettingsOverride($conf[$name]); + if ($this->useOverrides) { + if (isset($language_names[$name]) && isset($storage_data[$language_names[$name]])) { + $this->cache[$cache_key]->setLanguageOverride($storage_data[$language_names[$name]]); + } + if (isset($moduleOverrides[$name])) { + $this->cache[$cache_key]->setModuleOverride($moduleOverrides[$name]); + } + if (isset($conf[$name])) { + $this->cache[$cache_key]->setSettingsOverride($conf[$name]); + } } $list[$name] = $this->cache[$cache_key]; } diff --git a/core/lib/Drupal/Core/Datetime/Date.php b/core/lib/Drupal/Core/Datetime/Date.php index 81e7474..34b8632 100644 --- a/core/lib/Drupal/Core/Datetime/Date.php +++ b/core/lib/Drupal/Core/Datetime/Date.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Datetime; use Drupal\Component\Utility\Xss; +use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Language\Language; @@ -40,6 +41,13 @@ class Date { */ protected $languageManager; + /** + * The configuration factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + protected $country = NULL; protected $dateFormats = array(); @@ -72,10 +80,11 @@ class Date { * @param \Drupal\Core\StringTranslation\TranslationInterface $translation * The string translation. */ - public function __construct(EntityManagerInterface $entity_manager, LanguageManager $language_manager, TranslationInterface $translation) { + public function __construct(EntityManagerInterface $entity_manager, LanguageManager $language_manager, TranslationInterface $translation, ConfigFactory $config_factory) { $this->dateFormatStorage = $entity_manager->getStorageController('date_format'); $this->languageManager = $language_manager; $this->stringTranslation = $translation; + $this->configFactory = $config_factory; } /** @@ -205,9 +214,10 @@ protected function t($string, array $args = array(), array $options = array()) { protected function dateFormat($format, $langcode) { if (!isset($this->dateFormats[$format][$langcode])) { // Enter a language specific context so the right date format is loaded. - $original_language = config_factory_set_language(new Language(array('id' => $langcode))); + $original_language = $this->configFactory->getLanguage(); + $this->configFactory->setLanguage(new Language(array('id' => $langcode))); $this->dateFormats[$format][$langcode] = $this->dateFormatStorage->load($format); - config_factory_set_language($original_language); + $this->configFactory->setLanguage($original_language); } return $this->dateFormats[$format][$langcode]; } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php index e047806..3fe79bd 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php @@ -39,18 +39,12 @@ public function setUp() { } /** - * Tests basic locale override. - */ - function testConfigLocaleOverride() { - $name = 'config_test.system'; - $config = \Drupal::config($name); - $this->assertIdentical($config->get('foo'), 'en bar'); - } - - /** * Tests locale override based on language. */ function testConfigLocaleLanguageOverride() { + $config = \Drupal::config('config_test.system'); + $this->assertIdentical($config->get('foo'), 'en bar'); + language_save(new Language(array( 'name' => 'French', 'id' => 'fr', diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.php index b5014c4..f98a1e0 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.php @@ -54,6 +54,16 @@ function testSiteNameTranslation() { // The home page in English should not have the override. $this->drupalGet(''); $this->assertNoText('XX site name'); + + // During path resolution the system.site configuration object is used to + // determine the front page. This occurs before language negotiation causing + // the configuration factory to cache an object without the correct + // overrides. We are testing that the configuration factory is + // re-initialised after language negotiation. Ensure that it applies when + // we access the XX front page. + // @see \Drupal\Core\PathProcessor::processInbound() + $this->drupalGet('xx'); + $this->assertText('XX site name'); } -} +} diff --git a/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php b/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php index 264f156..50aaa88 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php @@ -9,6 +9,7 @@ use Drupal\config_translation\ConfigMapperManagerInterface; use Drupal\Core\Config\Config; +use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Config\Schema\Element; use Drupal\Core\Config\TypedConfigManager; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -92,12 +93,15 @@ * The translation storage object. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke the alter hook. + * @param \Drupal\Core\Config\ConfigFactory + * The config factory. */ - public function __construct(TypedConfigManager $typed_config_manager, ConfigMapperManagerInterface $config_mapper_manager, StringStorageInterface $locale_storage, ModuleHandlerInterface $module_handler) { + public function __construct(TypedConfigManager $typed_config_manager, ConfigMapperManagerInterface $config_mapper_manager, StringStorageInterface $locale_storage, ModuleHandlerInterface $module_handler, ConfigFactory $config_factory) { $this->typedConfigManager = $typed_config_manager; $this->configMapperManager = $config_mapper_manager; $this->localeStorage = $locale_storage; $this->moduleHandler = $module_handler; + $this->configFactory = $config_factory; } /** @@ -108,7 +112,8 @@ public static function create(ContainerInterface $container) { $container->get('config.typed'), $container->get('plugin.manager.config_translation.mapper'), $container->get('locale.storage'), - $container->get('module_handler') + $container->get('module_handler'), + $container->get('config.factory') ); } @@ -161,12 +166,13 @@ public function buildForm(array $form, array &$form_state, Request $request = NU // Get base language configuration to display in the form before entering // into the language context for the form. This avoids repetitively going // in and out of the language context to get original values later. - config_factory_disable_overrides(); + $this->configFactory->disableOverrides(); $this->baseConfigData = $this->mapper->getConfigData(); - config_factory_enable_overrides(); + $this->configFactory->enableOverrides(); // Set the translation target language on the configuration factory. - $original_language = config_factory_set_language($this->language); + $original_language = $this->configFactory->getLanguage(); + $this->configFactory->setLanguage($this->language); // Add some information to the form state for easier form altering. $form_state['config_translation_mapper'] = $this->mapper; @@ -192,7 +198,7 @@ public function buildForm(array $form, array &$form_state, Request $request = NU ); // Set the configuration language back. - config_factory_set_language($original_language); + $this->configFactory->setLanguage($original_language); return $form; } @@ -204,7 +210,7 @@ public function submitForm(array &$form, array &$form_state) { $form_values = $form_state['values']['config_names']; // For the form submission handling, use the raw data. - config_factory_disable_overrides(); + $this->configFactory->disableOverrides(); foreach ($this->mapper->getConfigNames() as $name) { // Set configuration values based on form submission and source values. $base_config = $this->config($name); @@ -222,7 +228,7 @@ public function submitForm(array &$form, array &$form_state) { $translation_config->save(); } } - config_factory_enable_overrides(); + $this->configFactory->enableOverrides(); $form_state['redirect_route'] = array( 'route_name' => $this->mapper->getOverviewRoute(), diff --git a/core/modules/locale/lib/Drupal/locale/ParamConverter/LocaleAdminPathConfigEntityConverter.php b/core/modules/locale/lib/Drupal/locale/ParamConverter/LocaleAdminPathConfigEntityConverter.php index 11719da..451746d 100644 --- a/core/modules/locale/lib/Drupal/locale/ParamConverter/LocaleAdminPathConfigEntityConverter.php +++ b/core/modules/locale/lib/Drupal/locale/ParamConverter/LocaleAdminPathConfigEntityConverter.php @@ -9,6 +9,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; +use Drupal\Core\Config\ConfigFactory; use Drupal\Core\ParamConverter\EntityConverter; use Drupal\Core\ParamConverter\ParamConverterInterface; @@ -29,15 +30,33 @@ class LocaleAdminPathConfigEntityConverter extends EntityConverter { /** + * The config factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** + * Constructs a new EntityConverter. + * + * @param \Drupal\Core\Entity\EntityManagerInterface $entityManager + * The entity manager. + */ + public function __construct(EntityManagerInterface $entity_manager, ConfigFactory $config_factory) { + $this->configFactory = $config_factory; + parent::__construct($entity_manager); + } + + /** * {@inheritdoc} */ public function convert($value, $definition, $name, array $defaults, Request $request) { $entity_type = substr($definition['type'], strlen('entity:')); if ($storage = $this->entityManager->getStorageController($entity_type)) { // Make sure no overrides are loaded. - config_factory_disable_overrides(); + $this->configFactory->disableOverrides(); $entity = $storage->load($value); - config_factory_enable_overrides(); + $this->configFactory->enableOverrides(); return $entity; } } diff --git a/core/modules/locale/locale.services.yml b/core/modules/locale/locale.services.yml index 688db5f..4d5792c 100644 --- a/core/modules/locale/locale.services.yml +++ b/core/modules/locale/locale.services.yml @@ -8,7 +8,7 @@ services: class: Drupal\locale\ParamConverter\LocaleAdminPathConfigEntityConverter tags: - { name: paramconverter, priority: 5 } - arguments: ['@entity.manager'] + arguments: ['@entity.manager', '@config.factory'] locale.config.typed: class: Drupal\locale\LocaleConfigManager arguments: ['@config.storage', '@config.storage.schema', '@config.storage.installer', '@locale.storage'] diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterRebuildTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterRebuildTest.php index 553a9e6..7cb4df5 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterRebuildTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterRebuildTest.php @@ -48,7 +48,7 @@ function setUp() { */ public function testMenuRouterRebuildContext() { // Enter a language context before rebuilding the menu router tables. - config_factory_set_language(language_load('nl')); + \Drupal::configFactory()->setLanguage(language_load('nl')); menu_router_rebuild(); // Check that the language context was not used for building the menu item. diff --git a/core/tests/Drupal/Tests/Core/Datetime/DateTest.php b/core/tests/Drupal/Tests/Core/Datetime/DateTest.php index 32d2103..55f2471 100644 --- a/core/tests/Drupal/Tests/Core/Datetime/DateTest.php +++ b/core/tests/Drupal/Tests/Core/Datetime/DateTest.php @@ -65,7 +65,7 @@ protected function setUp() { ->getMock(); $this->stringTranslation = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface'); - $this->date = new Date($this->entityManager, $this->languageManager, $this->stringTranslation); + $this->date = new Date($this->entityManager, $this->languageManager, $this->stringTranslation, $this->getConfigFactoryStub()); } /** diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php index 1c427f1..d1c59c9 100644 --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php @@ -8,8 +8,6 @@ namespace Drupal\Tests\Core\Routing; use Drupal\Component\Utility\Settings; -use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\NullStorage; use Drupal\Core\PathProcessor\PathProcessorAlias; use Drupal\Core\PathProcessor\PathProcessorManager; use Drupal\Core\Routing\UrlGenerator;