Commit b8073ec2 authored by catch's avatar catch

Issue #1936216 by stkrzysiak, kfritsche, Schnitzel, webflo, grisendo: Fixed...

Issue #1936216 by stkrzysiak, kfritsche, Schnitzel, webflo, grisendo: Fixed Configuration language selectors should have English even if English is not on the site.
parent c8b6e138
......@@ -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;
}
......
......@@ -7,6 +7,7 @@
namespace Drupal\menu\Tests;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Language\Language;
/**
......@@ -40,7 +41,7 @@ function setUp() {
$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 @@ function setUp() {
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 @@ function testMenuLanguage() {
$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');
}
}
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