Commit f8923c89 authored by catch's avatar catch

Issue #2684873 by alexpott, dawehner, Xano:...

Issue #2684873 by alexpott, dawehner, Xano: ConfigurableLanguageManager::getConfigOverrideLanguage() returns NULL
parent dd67ab2d
...@@ -14,7 +14,7 @@ services: ...@@ -14,7 +14,7 @@ services:
- { name: event_subscriber } - { name: event_subscriber }
language.config_factory_override: language.config_factory_override:
class: Drupal\language\Config\LanguageConfigFactoryOverride class: Drupal\language\Config\LanguageConfigFactoryOverride
arguments: ['@config.storage', '@event_dispatcher', '@config.typed'] arguments: ['@config.storage', '@event_dispatcher', '@config.typed', '@language.default']
tags: tags:
- { name: config.factory.override, priority: -254 } - { name: config.factory.override, priority: -254 }
- { name: event_subscriber } - { name: event_subscriber }
......
...@@ -68,11 +68,16 @@ class LanguageConfigFactoryOverride extends ConfigFactoryOverrideBase implements ...@@ -68,11 +68,16 @@ class LanguageConfigFactoryOverride extends ConfigFactoryOverrideBase implements
* An event dispatcher instance to use for configuration events. * An event dispatcher instance to use for configuration events.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
* The typed configuration manager. * The typed configuration manager.
* @param \Drupal\Core\Language\LanguageDefault $default_language
* The default language.
*/ */
public function __construct(StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config) { public function __construct(StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config, LanguageDefault $default_language) {
$this->baseStorage = $storage; $this->baseStorage = $storage;
$this->eventDispatcher = $event_dispatcher; $this->eventDispatcher = $event_dispatcher;
$this->typedConfigManager = $typed_config; $this->typedConfigManager = $typed_config;
// Prior to negiotiation the override language should be the default
// language.
$this->language = $default_language->get();
} }
/** /**
......
...@@ -36,6 +36,10 @@ public function setLanguage(LanguageInterface $language = NULL); ...@@ -36,6 +36,10 @@ public function setLanguage(LanguageInterface $language = NULL);
* The default language. * The default language.
* *
* @return $this * @return $this
*
* @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. This
* method has been replaced by injecting the default language into the
* constructor.
*/ */
public function setLanguageFromDefault(LanguageDefault $language_default = NULL); public function setLanguageFromDefault(LanguageDefault $language_default = NULL);
......
...@@ -54,13 +54,6 @@ public function alter(ContainerBuilder $container) { ...@@ -54,13 +54,6 @@ public function alter(ContainerBuilder $container) {
$container->setParameter('language.default_values', $default_language_values); $container->setParameter('language.default_values', $default_language_values);
} }
// For monolingual sites, we explicitly set the default language for the
// language config override service as there is no language negotiation.
if (!$this->isMultilingual()) {
$container->getDefinition('language.config_factory_override')
->addMethodCall('setLanguageFromDefault', array(new Reference('language.default')));
}
} }
/** /**
......
<?php
namespace Drupal\Tests\language\Kernel;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests \Drupal\language\Config\LanguageConfigFactoryOverride.
*
* @group language
*/
class LanguageConfigFactoryOverrideTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('system', 'language');
/**
* Tests language.config_factory_override service has the default language.
*/
public function testLanguageConfigFactoryOverride() {
$this->installConfig('system');
$this->installConfig('language');
/** @var \Drupal\language\Config\LanguageConfigFactoryOverride $config_factory_override */
$config_factory_override = \Drupal::service('language.config_factory_override');
$this->assertEquals('en', $config_factory_override->getLanguage()->getId());
ConfigurableLanguage::createFromLangcode('de')->save();
// Invalidate the container.
$this->config('system.site')->set('default_langcode', 'de')->save();
drupal_flush_all_caches();
$config_factory_override = \Drupal::service('language.config_factory_override');
$this->assertEquals('de', $config_factory_override->getLanguage()->getId());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment