From ea0ab7e57aa8bbea8ba099a6e4decca28024a536 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Mon, 3 Jun 2019 11:46:43 +0100 Subject: [PATCH] Issue #2939356 by Lendude, mediabounds, Manuel Garcia, validoll, justclint, hctom: Fatal error during import translaton of workflows.workflow.editorial.yml config --- .../locale/src/LocaleConfigSubscriber.php | 4 +- .../locale_test.translation_multiple.yml | 8 ++++ .../config/schema/locale_test.schema.yml | 37 +++++++++++++++++++ .../src/Kernel/LocaleConfigSubscriberTest.php | 22 ++++++++++- 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 core/modules/locale/tests/modules/locale_test/config/install/locale_test.translation_multiple.yml diff --git a/core/modules/locale/src/LocaleConfigSubscriber.php b/core/modules/locale/src/LocaleConfigSubscriber.php index d06cb34dec..7d7ff393e2 100644 --- a/core/modules/locale/src/LocaleConfigSubscriber.php +++ b/core/modules/locale/src/LocaleConfigSubscriber.php @@ -148,8 +148,8 @@ protected function processTranslatableData($name, array $config, array $translat continue; } if (is_array($item)) { - $reference_config = isset($reference_config[$key]) ? $reference_config[$key] : []; - $this->processTranslatableData($name, $config[$key], $item, $langcode, $reference_config); + $reference_config_item = isset($reference_config[$key]) ? $reference_config[$key] : []; + $this->processTranslatableData($name, $config[$key], $item, $langcode, $reference_config_item); } else { $this->saveCustomizedTranslation($name, $item->getUntranslatedString(), $item->getOption('context'), $config[$key], $langcode); diff --git a/core/modules/locale/tests/modules/locale_test/config/install/locale_test.translation_multiple.yml b/core/modules/locale/tests/modules/locale_test/config/install/locale_test.translation_multiple.yml new file mode 100644 index 0000000000..1be6abaead --- /dev/null +++ b/core/modules/locale/tests/modules/locale_test/config/install/locale_test.translation_multiple.yml @@ -0,0 +1,8 @@ +test: English test +test_multiple: + string: 'A string' + another_string: 'Another string' + test_after_multiple: false +test_after_multiple: + string: 'After a string' + another_string: 'After another string' diff --git a/core/modules/locale/tests/modules/locale_test/config/schema/locale_test.schema.yml b/core/modules/locale/tests/modules/locale_test/config/schema/locale_test.schema.yml index 958ce1b9c3..1f8ef08dee 100644 --- a/core/modules/locale/tests/modules/locale_test/config/schema/locale_test.schema.yml +++ b/core/modules/locale/tests/modules/locale_test/config/schema/locale_test.schema.yml @@ -19,3 +19,40 @@ locale_test.translation: label: 'Test' # See \Drupal\Tests\locale\Kernel\LocaleConfigSubscriberTest translatable: true + +locale_test.translation_multiple: + type: config_object + label: 'translation settings' + mapping: + test: + type: string + label: 'Test' + # See \Drupal\Tests\locale\Kernel\LocaleConfigSubscriberTest + translatable: true + test_multiple: + type: mapping + label: 'Multiple settings' + mapping: + string: + type: string + label: 'A string' + translatable: true + another_string: + type: string + label: 'Another string' + translatable: true + test_after_multiple: + type: boolean + label: 'Test after multiple' + test_after_multiple: + type: mapping + label: 'Test after multiple settings' + mapping: + string: + type: string + label: 'A string' + translatable: true + another_string: + type: string + label: 'Another string' + translatable: true diff --git a/core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php b/core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php index 67fdb1a97e..caa9a734fc 100644 --- a/core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php +++ b/core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php @@ -99,6 +99,7 @@ protected function setUpLocale() { // Set up the locale database the same way we have in the config samples. $this->setUpNoTranslation('locale_test.no_translation', 'test', 'Test', 'de'); $this->setUpTranslation('locale_test.translation', 'test', 'English test', 'German test', 'de'); + $this->setUpTranslation('locale_test.translation_multiple', 'test', 'English test', 'German test', 'de'); } /** @@ -111,6 +112,23 @@ public function testCreateTranslation() { $this->assertTranslation($config_name, 'Test (German)', 'de'); } + /** + * Tests creating translations configuration with multi value settings. + */ + public function testCreateTranslationMultiValue() { + $config_name = 'locale_test.translation_multiple'; + + $this->saveLanguageOverride($config_name, 'test_multiple', ['string' => 'String (German)', 'another_string' => 'Another string (German)'], 'de'); + $this->saveLanguageOverride($config_name, 'test_after_multiple', ['string' => 'After string (German)', 'another_string' => 'After another string (German)'], 'de'); + $strings = $this->stringStorage->getTranslations([ + 'type' => 'configuration', + 'name' => $config_name, + 'language' => 'de', + 'translated' => TRUE, + ]); + $this->assertCount(5, $strings); + } + /** * Tests importing community translations of shipped configuration. */ @@ -245,7 +263,7 @@ protected function setUpTranslation($config_name, $key, $source, $translation, $ * The configuration name. * @param string $key * The configuration key. - * @param string $value + * @param string|array $value * The configuration value to save. * @param string $langcode * The language code. @@ -446,7 +464,7 @@ protected function assertNoTranslation($config_name, $langcode) { * * @param string $config_name * The configuration name. - * @param string $translation + * @param string|array $translation * The translation. * @param string $langcode * The language code. -- GitLab