From 240524f08c22a03d3cc0c7d9a63bd88e898c9f1f Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Fri, 12 May 2017 10:58:42 +0100
Subject: [PATCH] Issue #2746253 by borisson_, Leksat, eiriksm, alexpott:
 Configuration translation save triggers an undefined index notice

---
 .../src/Form/ConfigTranslationFormBase.php    |  4 +-
 .../src/Tests/ConfigTranslationUiTest.php     | 40 +++++++++++++++++++
 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 82f01d714ab0..9f95a76cd0da 100644
--- a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php
+++ b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php
@@ -197,7 +197,7 @@ public function buildForm(array $form, FormStateInterface $form_state, RouteMatc
   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 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       $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 7ec350ba2c88..0a867e57d999 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\FieldStorageConfig;
 use Drupal\filter\Entity\FilterFormat;
 use Drupal\language\Entity\ConfigurableLanguage;
+use Drupal\node\Entity\NodeType;
 use Drupal\simpletest\WebTestBase;
 
 /**
@@ -1033,6 +1034,45 @@ public function testTextFormatTranslation() {
     $this->assertEqual($expected, $actual);
   }
 
+  /**
+   * 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.
    *
-- 
GitLab