summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-07-10 16:39:01 (GMT)
committer Alex Pott2013-07-10 16:39:01 (GMT)
commitfbec9433e8103fdc374f3aeae983856b5ed2609a (patch)
tree879f8a56024bb54cb66377b4b48bd0512ece39d9
parente29aaabd2eb5ffeaa3b33f33ae0eef865a0b18ea (diff)
Issue #2031197 by webflo, kfritsche, penyaskito: Language configuration entities should be created in English at all times.
-rw-r--r--core/modules/language/language.admin.inc2
-rw-r--r--core/modules/language/lib/Drupal/language/Plugin/Core/Entity/Language.php13
-rw-r--r--core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php13
-rw-r--r--core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php6
4 files changed, 30 insertions, 4 deletions
diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc
index aca6911..10506c6 100644
--- a/core/modules/language/language.admin.inc
+++ b/core/modules/language/language.admin.inc
@@ -187,7 +187,7 @@ function _language_admin_common_controls(&$form, $language = NULL) {
}
$form['name'] = array(
'#type' => 'textfield',
- '#title' => t('Language name'),
+ '#title' => t('Language name in English'),
'#maxlength' => 64,
'#default_value' => @$language->name,
'#required' => TRUE,
diff --git a/core/modules/language/lib/Drupal/language/Plugin/Core/Entity/Language.php b/core/modules/language/lib/Drupal/language/Plugin/Core/Entity/Language.php
index 4172e96..5991f9e 100644
--- a/core/modules/language/lib/Drupal/language/Plugin/Core/Entity/Language.php
+++ b/core/modules/language/lib/Drupal/language/Plugin/Core/Entity/Language.php
@@ -10,6 +10,8 @@ namespace Drupal\language\Plugin\Core\Entity;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Config\Entity\ConfigEntityBase;
+use Drupal\Core\Entity\EntityStorageControllerInterface;
+use Drupal\Core\Language\LanguageManager;
use Drupal\language\LanguageInterface;
/**
@@ -76,4 +78,15 @@ class Language extends ConfigEntityBase implements LanguageInterface {
*/
public $locked = FALSE;
+ /**
+ * {@inheritdoc}
+ */
+ public function preSave(EntityStorageControllerInterface $storage_controller) {
+ parent::preSave($storage_controller);
+ // Languages are picked from a predefined list which is given in English.
+ // For the uncommon case of custom languages the label should be given in
+ // English.
+ $this->langcode = 'en';
+ }
+
}
diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php
index 4bce384..f970bdd 100644
--- a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php
+++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php
@@ -51,6 +51,9 @@ class LanguageConfigurationTest extends WebTestBase {
$this->drupalPost('admin/config/regional/language/add', $edit, 'Add language');
$this->assertText('French');
$this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');
+ // Langcode for Languages is always 'en'.
+ $language = $this->container->get('config.factory')->get('language.entity.fr')->get();
+ $this->assertEqual($language['langcode'], 'en');
// Check if the Default English language has no path prefix.
$this->drupalGet('admin/config/regional/language/detection/url');
@@ -100,6 +103,16 @@ class LanguageConfigurationTest extends WebTestBase {
);
$this->drupalPost(NULL, $edit, t('Save configuration'));
$this->assertText(t('The prefix may not contain a slash.'), 'English prefix cannot be changed to contain a slash.');
+
+ // Remove English language and add a new Language to check if langcode of
+ // Language entity is 'en'.
+ $this->assert(language_delete('en'), 'Deleted English language.');
+ $edit = array(
+ 'predefined_langcode' => 'de',
+ );
+ $this->drupalPost('admin/config/regional/language/add', $edit, 'Add language');
+ $language = $this->container->get('config.factory')->get('language.entity.de')->get();
+ $this->assertEqual($language['langcode'], 'en');
}
/**
diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php
index f5875af..ff8086b 100644
--- a/core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php
+++ b/core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php
@@ -2,7 +2,7 @@
/**
* @file
- * Definition of Drupal\language\Tests\LanguageCustomConfigurationTest.
+ * Contains \Drupal\language\Tests\LanguageCustomConfigurationTest.
*/
namespace Drupal\language\Tests;
@@ -47,7 +47,7 @@ class LanguageCustomLanguageConfigurationTest extends WebTestBase {
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
// Test validation on missing values.
$this->assertText(t('!name field is required.', array('!name' => t('Language code'))));
- $this->assertText(t('!name field is required.', array('!name' => t('Language name'))));
+ $this->assertText(t('!name field is required.', array('!name' => t('Language name in English'))));
$empty_language = new Language();
$this->assertFieldChecked('edit-direction-' . $empty_language->direction, 'Consistent usage of language direction.');
$this->assertEqual($this->getUrl(), url('admin/config/regional/language/add', array('absolute' => TRUE)), 'Correct page redirection.');
@@ -61,7 +61,7 @@ class LanguageCustomLanguageConfigurationTest extends WebTestBase {
);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
$this->assertRaw(t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => t('Language code'))));
- $this->assertRaw(t('%field cannot contain any markup.', array('%field' => t('Language name'))));
+ $this->assertRaw(t('%field cannot contain any markup.', array('%field' => t('Language name in English'))));
$this->assertEqual($this->getUrl(), url('admin/config/regional/language/add', array('absolute' => TRUE)), 'Correct page redirection.');
// Test validation of existing language values.