diff --git a/core/includes/config.inc b/core/includes/config.inc index 00c7fa6..3ee2a78 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -257,11 +257,11 @@ function config_import_invoke_owner(array $config_changes, StorageInterface $sou // handle the configuration change. $handled_by_module = FALSE; if (module_exists($module) && module_hook($module, 'config_import_' . $op)) { - $old_config = new Config($name, $target_storage); + $old_config = new Config($name, $target_storage, language_default()); $old_config->load(); $data = $source_storage->read($name); - $new_config = new Config($name, $target_storage); + $new_config = new Config($name, $target_storage, language_default()); if ($data !== FALSE) { $new_config->setData($data); } diff --git a/core/includes/language.inc b/core/includes/language.inc index 74d5752..ea51ca2 100644 --- a/core/includes/language.inc +++ b/core/includes/language.inc @@ -466,11 +466,23 @@ function language_negotiation_method_invoke($method_id, $method = NULL, $request $results[$method_id] = isset($languages[$langcode]) ? $languages[$langcode] : FALSE; } - // Since objects are resources, we need to return a clone to prevent the - // language negotiation method cache from being unintentionally altered. The - // same methods might be used with different language types based on - // configuration. - return !empty($results[$method_id]) ? clone($results[$method_id]) : $results[$method_id]; + if (!empty($results[$method_id])) { + // Since objects are resources, we need to return a clone to prevent the + // language negotiation method cache from being unintentionally altered. The + // same methods might be used with different language types based on + // configuration. + $language = clone($results[$method_id]); + + // Set the negotiated language as the default for Config objects created by the + // ConfigFactory. + drupal_container() + ->get('config.factory') + ->setLanguage($language); + return $language; + } + else { + return FALSE; + } } /** diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 6fc2a87..899abf6 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Config; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Language\Language; use Symfony\Component\EventDispatcher\EventDispatcher; /** @@ -65,6 +66,13 @@ class Config { protected $eventDispatcher; /** + * The Language object used to override configuration data. + * + * @var Drupal\Core\Language\Language + */ + protected $language; + + /** * Constructs a configuration object. * * @param string $name @@ -72,12 +80,15 @@ class Config { * @param Drupal\Core\Config\StorageInterface $storage * A storage controller object to use for reading and writing the * configuration data. + * @param Drupal\Core\Language\Language $language + * The Language object used to override configuration data. * @param Symfony\Component\EventDispatcher\EventDispatcher $event_dispatcher * The event dispatcher used to notify subscribers. */ - public function __construct($name, StorageInterface $storage, EventDispatcher $event_dispatcher = NULL) { + public function __construct($name, StorageInterface $storage, Language $language, EventDispatcher $event_dispatcher = NULL) { $this->name = $name; $this->storage = $storage; + $this->language = $language; $this->eventDispatcher = $event_dispatcher ? $event_dispatcher : drupal_container()->get('dispatcher'); } @@ -416,4 +427,14 @@ public function merge(array $data_to_merge) { $this->data = NestedArray::mergeDeepArray(array($this->data, $data_to_merge), TRUE); return $this; } + + /** + * Returns the language object for this Config object. + * + * @return \Drupal\Core\Language\Language + */ + public function getLanguage() { + return $this->language; + } } + diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index ca36ce7..fef11a9 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Config; use Symfony\Component\EventDispatcher\EventDispatcher; +use Drupal\Core\Language\Language; /** * Defines the configuration object factory. @@ -46,10 +47,15 @@ class ConfigFactory { * configuration data. * @param Symfony\Component\EventDispatcher\EventDispatcher * An event dispatcher instance to use for configuration events. + * @param Drupal\Core\Language\Language + * A language object to inject in to configuration objects. */ - public function __construct(StorageInterface $storage, EventDispatcher $event_dispatcher) { + public function __construct(StorageInterface $storage, EventDispatcher $event_dispatcher, Language $language = NULL) { $this->storage = $storage; $this->eventDispatcher = $event_dispatcher; + // TODO: always inject language, once we figure out how to handle language + // and the DIC in early bootstrap phases. + $this->language = isset($language) ? $language : language_default(); } /** @@ -82,8 +88,27 @@ public function get($name) { // @todo The decrease of CPU time is interesting, since that means that // ContainerBuilder involves plenty of function calls (which are known to // be slow in PHP). - $config = new Config($name, $this->storage, $this->eventDispatcher); + $config = new Config($name, $this->storage, $this->language, $this->eventDispatcher); return $config->init(); } + /** + * Set the language to be injected in to Config objects. + * + * @param Language $language + * @return ConfigFactory + */ + public function setLanguage(Language $language) { + $this->language = $language; + return $this; + } + + /** + * Get the language to be injected in to Config objects. + * + * @return Drupal\Core\Language\Language + */ + public function getLanguage() { + return $this->language; + } } diff --git a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php index 3d2fd4a..4ae656d 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php @@ -26,7 +26,7 @@ class LocaleConfigSubscriber implements EventSubscriberInterface { */ public function configLoad(ConfigEvent $event) { $config = $event->getConfig(); - $language = language(LANGUAGE_TYPE_INTERFACE); + $language = $config->getLanguage(); $locale_name = $this->getLocaleConfigName($config->getName(), $language); if ($override = $config->getStorage()->read($locale_name)) { $config->setOverride($override); diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 7dabb6d..3db7f9e 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1989,8 +1989,28 @@ function user_view_multiple($accounts, $view_mode = 'full', $langcode = NULL) { function user_mail($key, &$message, $params) { $langcode = $message['langcode']; $variables = array('user' => $params['account']); + + $config_language = drupal_container() + ->get('config.factory') + ->getLanguage(); + $user_langcode = user_preferred_langcode($params['account']); + + if ($user_langcode != $config_language->langcode) { + // Make sure that we get configuration values for the user's language, not + // the site default language. + drupal_container() + ->get('config.factory') + ->setLanguage(language_load($user_langcode)); + } + $message['subject'] .= _user_mail_text($key . '.subject', $langcode, $variables); $message['body'][] = _user_mail_text($key . '.body', $langcode, $variables); + + if ($user_langcode != $config_language->langcode) { + drupal_container() + ->get('config.factory') + ->setLanguage($config_language); + } } /**