diff --git a/core/modules/config_translation/src/FormElement/FormElementBase.php b/core/modules/config_translation/src/FormElement/FormElementBase.php index e13cc31..ceca9c3 100644 --- a/core/modules/config_translation/src/FormElement/FormElementBase.php +++ b/core/modules/config_translation/src/FormElement/FormElementBase.php @@ -12,6 +12,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\language\Config\LanguageConfigOverride; +use Drupal\locale\SourceString; /** * Provides a common base class for form elements. @@ -66,11 +67,32 @@ public function getTranslationBuild(LanguageInterface $source_language, Language // configuration values in ConfigTranslationFormBase::setConfig(). // Therefore we make the 'source' and 'translation' keys the top-level // keys in $form_state['values']. - $build['source'] = $this->getSourceElement($source_language, $source_config); - $build['translation'] = $this->getTranslationElement($translation_language, $source_config, $translation_config); - $build['source']['#parents'] = array_merge(array('source'), $parents); - $build['translation']['#parents'] = array_merge(array('translation'), $parents); + // Cast into source string, will do for our purposes. + $source = new SourceString(array('source' => $translation_config)); + // Split source to work with plural values. + $source_array = $source->getPlurals(); + if (count($source_array) == 1) { + $build['source'] = $this->getSourceElement($source_language, $source_config); + $build['translation'] = $this->getTranslationElement($translation_language, $source_config, $translation_config); + + $build['source']['#parents'] = array_merge(array('source'), $parents); + $build['translation']['#parents'] = array_merge(array('translation'), $parents); + } + else { + $build['source'][0] = $this->getSourceElement($source_language, $source_array[0]); + $build['translation'][0] = $this->getTranslationElement($translation_language, $source_config, $source_array[0]); + + $build['source'][0]['#parents'] = array_merge(array('source'), $parents); + $build['translation'][0]['#parents'] = array_merge(array('translation'), $parents); + + $build['source'][1] = $this->getSourceElement($source_language, $source_array[1]); + $build['translation'][1] = $this->getTranslationElement($translation_language, $source_config, $source_array[1]); + + $build['source'][1]['#parents'] = array_merge(array('source'), $parents); + $build['translation'][1]['#parents'] = array_merge(array('translation'), $parents); + } + return $build; } @@ -83,7 +105,7 @@ public function getTranslationBuild(LanguageInterface $source_language, Language * translator. * * @param \Drupal\Core\Language\LanguageInterface $source_language - * Thee source language of the configuration object. + * The source language of the configuration object. * @param mixed $source_config * The configuration value of the element in the source language. *