summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2013-10-04 10:29:32 (GMT)
committerNathaniel Catchpole2013-10-04 10:29:32 (GMT)
commitb8073ec2113bae6316f1b9b4ae753d046f9ba6c0 (patch)
tree8a0ca1536185555175b73d370a7d3b221857b5fe
parentc8b6e138542f27040f1e994bc1d8372fb5cbe84c (diff)
Issue #1936216 by stkrzysiak, kfritsche, Schnitzel, webflo, grisendo: Fixed Configuration language selectors should have English even if English is not on the site.
-rw-r--r--core/modules/language/language.module15
-rw-r--r--core/modules/menu/lib/Drupal/menu/Tests/MenuLanguageTest.php37
2 files changed, 50 insertions, 2 deletions
diff --git a/core/modules/language/language.module b/core/modules/language/language.module
index b65e535..da06585 100644
--- a/core/modules/language/language.module
+++ b/core/modules/language/language.module
@@ -223,6 +223,21 @@ function language_process_language_select($element) {
$element['#options'][$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name;
}
}
+ // Add "Built-in English" language to the select when the default value is
+ // set to English but it does not exist in the options list.
+ //
+ // Drupal core includes configuration shipped in English, including default
+ // views, content types, user roles, filter formats, etc. To keep the Drupal
+ // software update-able, as well as translations update-able, we keep these
+ // configuration files in English even when installed in a foreign language.
+ // However, administrators can remove English, in which case editing such a
+ // configuration would lead to the language settings being changed on it. We
+ // avoid that by including this option and letting administrators keep it
+ // in English.
+ if (isset($element['#default_value']) && $element['#default_value'] == 'en' && !isset($element['#options']['en'])) {
+ // Prepend the default language at the beginning of the list.
+ $element['#options'] = array('en' => t('Built-in English')) + $element['#options'];
+ }
return $element;
}
diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuLanguageTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuLanguageTest.php
index d2d3b48..9e9af49 100644
--- a/core/modules/menu/lib/Drupal/menu/Tests/MenuLanguageTest.php
+++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuLanguageTest.php
@@ -7,6 +7,7 @@
namespace Drupal\menu\Tests;
+use Drupal\Component\Utility\Unicode;
use Drupal\Core\Language\Language;
/**
@@ -40,7 +41,7 @@ class MenuLanguageTest extends MenuWebTestBase {
$this->drupalLogin($this->admin_user);
// Add some custom languages.
- foreach (array('aa', 'bb', 'cc') as $language_code) {
+ foreach (array('aa', 'bb', 'cc', 'cs') as $language_code) {
$language = new Language(array(
'id' => $language_code,
'name' => $this->randomName(),
@@ -55,7 +56,7 @@ class MenuLanguageTest extends MenuWebTestBase {
function testMenuLanguage() {
// Create a test menu to test the various language-related settings.
// Machine name has to be lowercase.
- $menu_name = drupal_strtolower($this->randomName(16));
+ $menu_name = Unicode::strtolower($this->randomName(16));
$label = $this->randomString();
$edit = array(
'id' => $menu_name,
@@ -157,4 +158,36 @@ class MenuLanguageTest extends MenuWebTestBase {
$this->assertNoField('edit-langcode', 'The language selector field was hidden the page');
}
+ /**
+ * Tests menu configuration is still English after English has been deleted.
+ */
+ function testMenuLanguageRemovedEnglish() {
+ // Create a test menu to test language settings.
+ // Machine name has to be lowercase.
+ $menu_name = Unicode::strtolower($this->randomName(16));
+ $edit = array(
+ 'id' => $menu_name,
+ 'description' => '',
+ 'label' => $this->randomString(),
+ 'langcode' => 'en',
+ );
+ $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
+
+ // Check that the language settings were saved.
+ $menu = menu_load($menu_name);
+ $this->assertEqual($menu->langcode, 'en');
+
+ // Remove English language. To do that another language has to be set as
+ // default.
+ $language = language_load('cs');
+ $language->default = TRUE;
+ language_save($language);
+ language_delete('en');
+
+ // Save the menu again and check if the language is still the same.
+ $this->drupalPostForm("admin/structure/menu/manage/$menu_name", array(), t('Save'));
+ $menu = menu_load($menu_name);
+ $this->assertEqual($menu->langcode, 'en');
+ }
+
}