diff --git a/core/modules/config_translation/src/FormElement/ListElement.php b/core/modules/config_translation/src/FormElement/ListElement.php index 8bd8a52..b3f609e 100644 --- a/core/modules/config_translation/src/FormElement/ListElement.php +++ b/core/modules/config_translation/src/FormElement/ListElement.php @@ -54,8 +54,7 @@ public function getTranslationBuild(LanguageInterface $source_language, Language $build = array(); foreach ($this->element as $key => $element) { $sub_build = array(); - // Make the specific element key, "$base_key.$key". - $element_key = implode('.', array_filter(array($base_key, $key))); + $element_key = $this->getElementKey($base_key, $key); $definition = $element->getDataDefinition(); if ($form_element = ConfigTranslationFormBase::createFormElement($element)) { @@ -88,7 +87,7 @@ public function getTranslationBuild(LanguageInterface $source_language, Language */ public function setConfig(Config $base_config, LanguageConfigOverride $config_translation, $config_values, $base_key = NULL) { foreach ($this->element as $key => $element) { - $element_key = implode('.', array_filter(array($base_key, $key))); + $element_key = $this->getElementKey($base_key, $key); if ($form_element = ConfigTranslationFormBase::createFormElement($element)) { // Traverse into the next level of the configuration. $value = isset($config_values[$key]) ? $config_values[$key] : NULL; @@ -134,4 +133,23 @@ protected function getGroupTitle(DataDefinitionInterface $definition, array $gro return (!empty($title) ? (strip_tags($title) . ' ') : '') . $this->t($definition['label']); } + /** + * Gets a compound element key. + * + * Should be used for building an element key when recursively iterating over + * the schema element. + * + * @param string|null $base_key + * The base key or NULL if this is the top-level element. + * @param string $key + * The sub-key. + * + * @return string + * The compound element key. + */ + protected function getElementKey($base_key, $key) { + // Account for the fact that $base_key might be NULL. + return ltrim("$base_key.$key", '.'); + } + } diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php index 8671c3c..ae0d250 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php @@ -703,6 +703,46 @@ public function testAlterInfo() { } /** + * Tests the sequence data type translation. + */ + public function testSequenceTranslation() { + $this->drupalLogin($this->adminUser); + /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */ + $config_factory = $this->container->get('config.factory'); + + $expected = array( + 'kitten', + 'llama', + 'elephant' + ); + $actual = $config_factory + ->getEditable('config_translation_test.content') + ->get('animals'); + $this->assertEqual($expected, $actual); + + $edit = array( + 'translation[config_names][config_translation_test.content][content][value]' => '
Hello World - FR
', + 'translation[config_names][config_translation_test.content][animals][0]' => 'kitten - FR', + 'translation[config_names][config_translation_test.content][animals][1]' => 'llama - FR', + 'translation[config_names][config_translation_test.content][animals][2]' => 'elephant - FR', + ); + $this->drupalPostForm('admin/config/media/file-system/translate/fr/add', $edit, t('Save translation')); + + $this->container->get('language.config_factory_override') + ->setLanguage(new Language(array('id' => 'fr'))); + + $expected = array( + 'kitten - FR', + 'llama - FR', + 'elephant - FR', + ); + $actual = $config_factory + ->get('config_translation_test.content') + ->get('animals'); + $this->assertEqual($expected, $actual); + } + + /** * Test text_format translation. */ public function testTextFormatTranslation() { diff --git a/core/modules/config_translation/tests/modules/config_translation_test/config/install/config_translation_test.content.yml b/core/modules/config_translation/tests/modules/config_translation_test/config/install/config_translation_test.content.yml index 5a4d4bb..307db48 100644 --- a/core/modules/config_translation/tests/modules/config_translation_test/config/install/config_translation_test.content.yml +++ b/core/modules/config_translation/tests/modules/config_translation_test/config/install/config_translation_test.content.yml @@ -4,3 +4,7 @@ langcode: en content: value: "Hello World
" format: plain_text +animals: + - kitten + - llama + - elephant diff --git a/core/modules/config_translation/tests/modules/config_translation_test/config/schema/config_translation_test.schema.yml b/core/modules/config_translation/tests/modules/config_translation_test/config/schema/config_translation_test.schema.yml index 757448f..4e43d5f 100644 --- a/core/modules/config_translation/tests/modules/config_translation_test/config/schema/config_translation_test.schema.yml +++ b/core/modules/config_translation/tests/modules/config_translation_test/config/schema/config_translation_test.schema.yml @@ -16,3 +16,9 @@ config_translation_test.content: content: type: text_format label: 'Content' + animals: + type: sequence + label: 'Animals' + sequence: + - type: label +