diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml index edeba4f5..0295bf0 100644 --- a/core/config/schema/core.data_types.schema.yml +++ b/core/config/schema/core.data_types.schema.yml @@ -219,11 +219,11 @@ config_dependencies: text_with_format: type: mapping label: 'Text with format' - translatable: true mapping: value: type: text label: 'Content' + translatable: true format: type: string label: 'Text format' diff --git a/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php b/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php index 8d76ede..8d60281 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Form/ConfigTranslationFormBase.php @@ -198,7 +198,7 @@ public function buildForm(array $form, array &$form_state, Request $request = NU ); foreach ($this->mapper->getConfigNames() as $name) { $form['config_names'][$name] = array('#type' => 'container'); - $form['config_names'][$name] += $this->buildConfigForm($this->typedConfigManager->get($name), $this->config($name)->get(), $this->baseConfigData[$name]); + $form['config_names'][$name] += $this->buildConfigForm($name, $this->typedConfigManager->get($name), $this->config($name)->get(), $this->baseConfigData[$name]); } $form['actions']['#type'] = 'actions'; @@ -252,6 +252,8 @@ public function submitForm(array &$form, array &$form_state) { /** * Formats configuration schema as a form tree. * + * @param string $name + * The configuration name. * @param \Drupal\Core\Config\Schema\Element $schema * Schema definition of configuration. * @param array|string $config_data @@ -269,7 +271,7 @@ public function submitForm(array &$form, array &$form_state) { * @return array * An associative array containing the structure of the form. */ - protected function buildConfigForm(Element $schema, $config_data, $base_config_data, $open = TRUE, $base_key = '') { + protected function buildConfigForm($name, Element $schema, $config_data, $base_config_data, $open = TRUE, $base_key = '') { $build = array(); foreach ($schema as $key => $element) { // Make the specific element key, "$base_key.$key". @@ -288,7 +290,7 @@ protected function buildConfigForm(Element $schema, $config_data, $base_config_d if ($element instanceof Element && !isset($definitions[$element_type]['form_element_class'])) { // Build sub-structure and include it with a wrapper in the form // if there are any translatable elements there. - $sub_build = $this->buildConfigForm($element, $config_data[$key], $base_config_data[$key], FALSE, $element_key); + $sub_build = $this->buildConfigForm($name, $element, $config_data[$key], $base_config_data[$key], FALSE, $element_key); if (!empty($sub_build)) { // For some configuration elements the same element structure can // repeat multiple times, (like views displays, filters, etc.). @@ -331,6 +333,7 @@ protected function buildConfigForm(Element $schema, $config_data, $base_config_d ) ), '#type' => 'item', + '#input' => FALSE, ); /** @var \Drupal\config_translation\FormElement\ElementInterface $form_element */ @@ -338,6 +341,7 @@ protected function buildConfigForm(Element $schema, $config_data, $base_config_d $build[$element_key]['source']['#markup'] = $form_element->getRenderedSource($base_config_data, $key, $this->sourceLanguage, $this->language); $build[$element_key]['translation'] = $form_element->getFormElement($definition, $this->language, $value); + $build[$element_key]['translation']['#parents'] = array_merge(array('config_names', $name), explode('.', $element_key)); } } return $build; @@ -372,11 +376,17 @@ protected function buildConfigForm(Element $schema, $config_data, $base_config_d * @return array * Translation configuration override data. */ - protected function setConfig(Language $language, Config $base_config, Config $config_translation, array $config_values, Element $schema, $shipped_config = FALSE) { - foreach ($config_values as $key => $value) { - if (is_array($value) && !isset($value['translation'])) { + protected function setConfig(Language $language, Config $base_config, Config $config_translation, array $config_values, Element $schema, $shipped_config = FALSE, $base_key = NULL) { + foreach ($schema as $key => $element) { + if (!isset($config_values[$key])) { + continue; + } + $element_key = implode('.', array_filter(array($base_key, $key))); + $definition = $element->getDataDefinition(); + $value = $config_values[$key]; + if ($element instanceof Element && empty($definition['translatable'])) { // Traverse into this level in the configuration. - $this->setConfig($language, $base_config, $config_translation, $value, $schema, $shipped_config); + $this->setConfig($language, $base_config, $config_translation, $value, $element, $shipped_config, $element_key); } else { // If the configuration file being translated was originally shipped, we @@ -418,9 +428,9 @@ protected function setConfig(Language $language, Config $base_config, Config $co /** @var \Drupal\config_translation\FormElement\ElementInterface $form_element */ $form_element = new $definition['form_element_class'](); - $translation_string = $form_element->getTranslationString($value['translation']); + $translation_string = $form_element->getTranslationString($value); } else { - $translation_string = $value['translation']; + $translation_string = $value; } // If we have a new translation or different from what is stored in @@ -434,8 +444,8 @@ protected function setConfig(Language $language, Config $base_config, Config $co // Save value, if different from the source value in the base // configuration. If same as original configuration, remove override. - if ($base_config->get($key) !== $value['translation']) { - $config_translation->set($key, $value['translation']); + if ($base_config->get($key) !== $value) { + $config_translation->set($element_key, $value); } else { $config_translation->clear($key);