diff --git a/core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php index 3e00a91..66fdd61 100644 --- a/core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/LanguageRequestSubscriber.php @@ -18,8 +18,20 @@ */ class LanguageRequestSubscriber implements EventSubscriberInterface { + /** + * The language manager service + * + * @var \Drupal\Core\Language\LanguageManager + */ protected $languageManager; + /** + * Constructs a LanguageRequestSubscriber object. + * + * @param \Drupal\Core\Language\LanguageManager $language_manager + * The language manager service. + * + */ public function __construct(LanguageManager $language_manager) { $this->languageManager = $language_manager; } diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index 5ee33d9..88436df 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -51,7 +51,7 @@ public function init() { if ($this->initialized) { return; } - if ($this->getLanguageCount() > 1) { + if ($this->isMultilingual()) { foreach ($this->getLanguageTypes() as $type) { $this->getLanguage($type); } @@ -61,6 +61,9 @@ public function init() { /** * Sets the $request property and resets all language types. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * The HttpRequest object representing the current request. */ public function setRequest(Request $request) { $this->request = $request; @@ -70,16 +73,24 @@ public function setRequest(Request $request) { /** * Returns a language object for the given type. + * + * @param string $type + * The language type, e.g. LANGUAGE_TYPE_INTERFACE. + * + * @return \Drupal\Core\Language\Language + * A language object for the given type. */ public function getLanguage($type) { if (isset($this->languages[$type])) { return $this->languages[$type]; } - // @todo Objectify the language system so that we don't have to do this. - if ($this->getLanguageCount() > 1 && $this->request) { + if ($this->isMultilingual() && $this->request) { if (!$this->initializing) { $this->initializing = TRUE; + // @todo Objectify the language system so that we don't have to do load + // an include file and call out to procedural code. See + // http://drupal.org/node/1862202 include_once DRUPAL_ROOT . '/core/includes/language.inc'; $this->languages[$type] = language_types_initialize($type, $this->request); $this->initializing = FALSE; @@ -89,17 +100,21 @@ public function getLanguage($type) { // type. Simply return the default language without setting it on the // $this->languages property. See the TODO in the docblock for the // $initializing property. - return new Language($this->getLanguageDefault() + array('default' => TRUE)); + return $this->getLanguageDefault(); } } else { - $this->languages[$type] = new Language($this->getLanguageDefault() + array('default' => TRUE)); + $this->languages[$type] = $this->getLanguageDefault(); } return $this->languages[$type]; } /** * Resets the given language type or all types if none specified. + * + * @param string $type + * The language type to reset, e.g. LANGUAGE_TYPE_INTERFACE, or NULL to reset + * all language types. */ public function reset($type = NULL) { if (!isset($type)) { @@ -112,35 +127,39 @@ public function reset($type = NULL) { } /** - * @todo Inject state once these variables have been converted to use the - * state system, then remove these methods and replace calls to them with - * $this->state->get('language_count') etc. - */ - - /** - * Returns the number of currently enabled langauges. + * Returns whether or not the site has more than one language enabled. + * + * @return boolean + * TRUE if more than one language is enabled, FALSE otherwise. */ - protected function getLanguageCount() { - return variable_get('language_count', 1); + protected function isMultilingual() { + return variable_get('language_count', 1) > 1; } /** - * Returns the array of language types. + * Returns an array of the available language types. + * + * @return array() + * An array of all language types. */ protected function getLanguageTypes() { return array_keys(variable_get('language_types', language_types_get_default())); } /** - * Returns an array of information representing the current default language. + * Returns a langauge object representing the site's default language. + * + * @return Drupal\Core\Language\Language + * A language object. */ protected function getLanguageDefault() { - return variable_get('language_default', array( + $default_info = variable_get('language_default', array( 'langcode' => 'en', 'name' => 'English', 'direction' => 0, 'weight' => 0, 'locked' => 0, )); + return new Language($default_info + array('default' => TRUE)); } } diff --git a/core/modules/language/language.negotiation.inc b/core/modules/language/language.negotiation.inc index c654d84..ee977c1 100644 --- a/core/modules/language/language.negotiation.inc +++ b/core/modules/language/language.negotiation.inc @@ -206,6 +206,9 @@ function language_from_user($languages) { * @param $languages * An array of valid language objects. * + * @param $request + * The HttpRequest object representing the current request. + * * @return * A valid language code on success, FALSE otherwise. */ diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php index 465a4b9..c9ae95a 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php @@ -57,9 +57,11 @@ function testUninstallProcess() { )); language_save($language); // Reset the language manager. - $this->container->get('language_manager')->reset(); + $language_manager = $this->container->get('language_manager'); + $language_manager->reset(); + $language_manager->init(); // Check the UI language. - drupal_language_initialize(); + $this->assertEqual(language(LANGUAGE_TYPE_INTERFACE)->langcode, $this->langcode, t('Current language: %lang', array('%lang' => language(LANGUAGE_TYPE_INTERFACE)->langcode))); // Enable multilingual workflow option for articles.