diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 6fc2a87..eecc5eb 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 getLanuage() { + return $this->language; + } } + diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index ca36ce7..4956305 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,19 @@ 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; + } + } 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);