Commit 7c1ef6ed authored by Dries's avatar Dries

- Patch #1627208 by vasi1186: make language_list() and language_default()...

- Patch #1627208 by vasi1186: make language_list() and language_default() return instances of Language.
parent 33a56047
......@@ -5,6 +5,7 @@
use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Language\Language;
/**
* @file
......@@ -2676,18 +2677,19 @@ function language_list() {
$default = language_default();
if (language_multilingual() || module_exists('language')) {
// Use language module configuration if available.
$languages = db_query('SELECT * FROM {language} ORDER BY weight ASC, name ASC')->fetchAllAssoc('langcode');
$languages = db_query('SELECT * FROM {language} ORDER BY weight ASC, name ASC')->fetchAllAssoc('langcode', PDO::FETCH_ASSOC);
// Initialize default property so callers have an easy reference and can
// save the same object without data loss.
foreach ($languages as $langcode => $info) {
$info['default'] = ($langcode == $default->langcode);
$languages[$langcode] = new Language($info);
}
}
else {
// No language module, so use the default language only.
$languages = array($default->langcode => $default);
}
// Initialize default property so callers have an easy reference and can
// save the same object without data loss.
foreach ($languages as $langcode => $language) {
$languages[$langcode]->default = ($langcode == $default->langcode);
}
}
return $languages;
......@@ -2737,14 +2739,14 @@ function language_name($langcode) {
* A language object.
*/
function language_default() {
$default = variable_get('language_default', (object) array(
$info = variable_get('language_default', array(
'langcode' => 'en',
'name' => 'English',
'direction' => 0,
'weight' => 0,
));
$default->default = TRUE;
return $default;
$info['default'] = TRUE;
return new Language($info);
}
/**
......
......@@ -218,7 +218,10 @@ function update_prepare_d8_language() {
unset($language_default->language);
}
unset($language_default->enabled);
variable_set('language_default', $language_default);
// In D8, the 'language_default' is not anymore an object, but an array,
// so make sure that the new value that is saved into this variable is an
// array.
variable_set('language_default', (array) $language_default);
}
}
}
......
......@@ -184,7 +184,7 @@ function language_save($language) {
if (!empty($language->default)) {
// Set the new version of this language as default in a variable.
$default_language = language_default();
variable_set('language_default', $language);
variable_set('language_default', (array) $language);
}
// Update language count based on enabled language count.
......
......@@ -57,7 +57,7 @@ function testDependencyInjectedNewLanguage() {
// Initialize the language system.
drupal_language_initialize();
$expected = new Language((array) language_default());
$expected = language_default();
$result = drupal_container()->get(LANGUAGE_TYPE_INTERFACE);
foreach ($expected as $property => $value) {
$this->assertEqual($expected->$property, $result->$property, t('The dependency injected language object %prop property equals the new Language object %prop property.', array('%prop' => $property)));
......@@ -72,7 +72,7 @@ function testDependencyInjectedNewLanguage() {
*/
function testDependencyInjectedNewDefaultLanguage() {
// Change the language default object to different values.
$new_language_default = (object) array(
$new_language_default = array(
'langcode' => 'fr',
'name' => 'French',
'direction' => 0,
......@@ -86,7 +86,7 @@ function testDependencyInjectedNewDefaultLanguage() {
// The langauge system creates a Language object which contains the
// same properties as the new default language object.
$expected = $new_language_default;
$expected = new Language($new_language_default);
$result = drupal_container()->get(LANGUAGE_TYPE_INTERFACE);
foreach ($expected as $property => $value) {
$this->assertEqual($expected->$property, $result->$property, t('The dependency injected language object %prop property equals the default language object %prop property.', array('%prop' => $property)));
......
......@@ -93,7 +93,7 @@ function testUILanguageNegotiation() {
// be some bug.
drupal_static_reset('language_list');
$languages = language_list();
variable_set('language_default', $languages['vi']);
variable_set('language_default', (array) $languages['vi']);
// First visit this page to make sure our target string is searchable.
$this->drupalGet('admin/config');
// Now the t()'ed string is in db so switch the language back to default.
......
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