summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2017-05-12 10:58:42 +0100
committerAlex Pott2017-05-12 10:58:42 +0100
commit240524f08c22a03d3cc0c7d9a63bd88e898c9f1f (patch)
tree5ceece2115b192a73405eb7237bd7180cfaadef7
parenta9fe99c7cbb597fc5f149986876cad83d3e7f20d (diff)
Issue #2746253 by borisson_, Leksat, eiriksm, alexpott: Configuration translation save triggers an undefined index notice
-rw-r--r--core/modules/config_translation/src/Form/ConfigTranslationFormBase.php4
-rw-r--r--core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php40
2 files changed, 42 insertions, 2 deletions
diff --git a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php
index 82f01d7..9f95a76 100644
--- a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php
+++ b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php
@@ -197,7 +197,7 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_values = $form_state->getValue(['translation', 'config_names']);
- foreach ($this->mapper->getConfigNames() as $name) {
+ foreach ($form_values as $name => $value) {
$schema = $this->typedConfigManager->get($name);
// Set configuration values based on form submission and source values.
@@ -205,7 +205,7 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
$config_translation = $this->languageManager->getLanguageConfigOverride($this->language->getId(), $name);
$element = $this->createFormElement($schema);
- $element->setConfig($base_config, $config_translation, $form_values[$name]);
+ $element->setConfig($base_config, $config_translation, $value);
// If no overrides, delete language specific configuration file.
$saved_config = $config_translation->get();
diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php
index 7ec350b..0a867e5 100644
--- a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php
+++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php
@@ -12,6 +12,7 @@ use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\filter\Entity\FilterFormat;
use Drupal\language\Entity\ConfigurableLanguage;
+use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase;
/**
@@ -1034,6 +1035,45 @@ class ConfigTranslationUiTest extends WebTestBase {
}
/**
+ * Tests field translation for node fields.
+ */
+ public function testNodeFieldTranslation() {
+ NodeType::create(['type' => 'article', 'name' => 'Article'])->save();
+
+ $field_name = 'translatable_field';
+ $field_storage = FieldStorageConfig::create([
+ 'field_name' => $field_name,
+ 'entity_type' => 'node',
+ 'type' => 'text',
+ ]);
+
+ $field_storage->setSetting('translatable_storage_setting', 'translatable_storage_setting');
+ $field_storage->save();
+ $field = FieldConfig::create([
+ 'field_name' => $field_name,
+ 'entity_type' => 'node',
+ 'bundle' => 'article',
+ ]);
+ $field->save();
+
+ $this->drupalLogin($this->translatorUser);
+
+ $this->drupalGet("/entity_test/structure/article/fields/node.article.$field_name/translate");
+ $this->clickLink('Add');
+
+ $form_values = [
+ 'translation[config_names][field.field.node.article.translatable_field][description]' => 'FR Help text.',
+ 'translation[config_names][field.field.node.article.translatable_field][label]' => 'FR label',
+ ];
+ $this->drupalPostForm(NULL, $form_values, 'Save translation');
+ $this->assertText('Successfully saved French translation.');
+
+ // Check that the translations are saved.
+ $this->clickLink('Add');
+ $this->assertRaw('FR label');
+ }
+
+ /**
* Gets translation from locale storage.
*
* @param $config_name