Problem/Motivation

The default values of text fields do not use the text_format schema type which was introduced in #2144413: Config translation does not support text elements with a format. This means that the default value of text fields can not be properly translated currently.

Note that this is not only a UX problem (i.e. no CKEditor for translators) but can also lead to security problems.

Proposed resolution

Use the text_format schema type where appropriate.

The text_with_summary field type has a slightly different structure (i.e. it has an additional summary key) so a dedicated schema type is introduced for that. In order to leverage that, a dedicated Config Translation form element is added, to allow that to be translated. Note that this could be split off and handled in a follow-up.

Remaining tasks

User interface changes

Default values of text fields can be translated using a text editor.

API changes

The schema structure of text fields changes (specifically of the default value declaration). Note that the config structure itself does not change!

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because default values of text fields cannot be translated with the Config Translation module without this
Issue priority Normal
Unfrozen changes Not unfrozen
Prioritized changes The main goal of this issue is usability and security.
Disruption Because the actual config structure does not change I cannot possibly fathom whom this would "disrupt". Because the configuration schema structure changes, it is an API change, however, strictly speaking.

Issue fork drupal-2381147

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler’s picture

Assigned: Unassigned » tstoeckler

I'm actually working on this. If I haven't managed to post a patch in ~3 days or something feel free to take this over.

tstoeckler’s picture

Issue tags: +D8MI, +language-config, +sprint
Gábor Hojtsy’s picture

Changes config schema, so D8 upgrade path tag should be on.

tstoeckler’s picture

Here we go.

Some problems:

  1. This can not be tested currently with the text field type (only the text_long and text_with_summary types) due to #2348459: Fields of type 'Text (formatted)' do NOT save values..
  2. Configuration Translation's form generation is broken for sequences with multiple items. I will open a separate issue for that.
  3. We do not currently generate any sensible labels for sequences, we just duplicate the same one each time. I will open a separate issue for that.
  4. The Hide summary/Show summary link should not be displayed for a disabled textarea it makes no sense. Will open a separate issue for that.

See also the attached screenshot for some context:
A screenshot of the Configuration Translation UI to translate the default value of a text field with a summary

Re #3: How specifically is this related to the upgrade path, I don't understand that?

Edit: Duplicate post

Gábor Hojtsy’s picture

Issue tags: -D8 upgrade path

Ok this does not actually change the config data structure like #2144505: Views does not use the text format type for formatted text, so this does not need the D8 upgrade path tag. I assumed it will change the data structure, but looks like it does not.

Gábor Hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

#2348459: Fields of type 'Text (formatted)' do NOT save values. landed. Should be possible to write tests for this now?

Gábor Hojtsy’s picture

Title: Use 'text_format' schema type for text field default values » Text and text with summary field default value config does not use the text_format schema type
Gábor Hojtsy’s picture

@tstoeckler: still working in this one or should we look for someone else to finish?

Gábor Hojtsy’s picture

Issue tags: -sprint

Unfortunately not being actively worked on so removing from sprint.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anybody’s picture

I can confirm this issue still exists.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
7.38 KB

First a re-roll.

tstoeckler’s picture

Assigned: tstoeckler » Unassigned
Issue tags: -Needs tests
FileSize
3.84 KB
9.53 KB

The previous run was green, even though it never reported back.

Now adding a test. The tests-only patch is also the interdiff.

Unassigning as I'm not sure, when I'll get back to this.

tstoeckler’s picture

Oops sorry. Completely wrong patch files.

The last submitted patch, 17: 2921844-6.patch, failed testing. View results

The last submitted patch, 18: 2381147-17--tests-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative, +Needs reroll
AkashKumar07’s picture

Status: Needs work » Needs review
FileSize
8.06 KB

Reroll added for patch #18.

smustgrave’s picture

Status: Needs review » Needs work

patch failed

smustgrave’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
838 bytes
8.09 KB

Status: Needs review » Needs work

The last submitted patch, 30: 2381147-30.patch, failed testing. View results

smustgrave’s picture

Okay I found the issue. The patch in #28 removed changes from #18 and I didn't notice that in my attempt at #30.

For the committer please update credit to match.

Rerolled #18 correctly.

Attempted to create an interdiff but got
1 out of 2 hunks FAILED -- saving rejects to file /var/folders/z8/ym9ls3bj01x19hd8xfvsyk_40000gn/T//interdiff-1.FQffex.rej
interdiff: Error applying patch1 to reconstructed file

The last submitted patch, 32: 2381147-32-tests-only.patch, failed testing. View results

smustgrave’s picture

Version: 9.4.x-dev » 10.1.x-dev
FileSize
0 bytes
10.57 KB
gaurav-mathur’s picture

Assigned: Unassigned » gaurav-mathur
gaurav-mathur’s picture

Assigned: gaurav-mathur » Unassigned

Hi I've tested this patch #34 on drupal 10.1.x and it works.

jungle’s picture

First, posting the raw interdiff content of 0 bytes interdiff-32-33.txt

$ diff 2381147-32.patch 2381147-33.patch
83c83
< index 42d54b21ef..d1d7bad78f 100644
---
> index f60c0a56ee..fc053f29f8 100644
94c94
< @@ -1108,6 +1109,70 @@ public function testMenuTranslationWithoutChange() {
---
> @@ -1111,6 +1112,70 @@ public function testMenuTranslationWithoutChange() {
191c191
< index 08bc9aad87..5a9f3ac4f4 100644
---
> index e0fa5d3d83..ae2ab6ee2f 100644
194,195c194,195
< @@ -21,15 +21,8 @@ field.field_settings.text:
<    label: 'Text (formatted) settings'
---
> @@ -27,15 +27,8 @@ field.field_settings.text:
>          type: string
211,212c211,212
< @@ -40,15 +33,8 @@ field.field_settings.text_long:
<    type: mapping
---
> @@ -52,15 +45,8 @@ field.field_settings.text_long:
>          type: string
228,229c228,229
< @@ -66,18 +52,8 @@ field.field_settings.text_with_summary:
<        label: 'Require summary'
---
> @@ -83,18 +69,8 @@ field.field_settings.text_with_summary:
>          type: string

jungle’s picture

2. review the schema changes

Posting the schema of text_format from core/config/schema/core.data_types.schema.yml

# Text with a text format.
text_format:
  type: mapping
  label: 'Text with text format'
  # We declare the entire mapping of text and text format as translatable. This
  # causes the entire mapping to be saved to the language overrides of the
  # configuration. Storing only the (to be formatted) text could result in
  # security problems in case the text format of the source text is changed.
  translatable: true
  mapping:
    value:
      type: text
      label: 'Text'
      # Mark the actual text as translatable (in addition to the entire mapping
      # being marked as translatable) so that shipped configuration with
      # formatted text can participate in the string translation system.
      translatable: true
    format:
      type: string
      label: 'Text format'
      # The text format should not be translated as part of the string
      # translation system, so this is not marked as translatable.
+++ b/core/modules/text/config/schema/text.data_types.schema.yml
@@ -0,0 +1,19 @@
+# See the 'text_format' type in core.data_types.schema.yml.
+text_format_with_summary:
+  label: 'Default'
+  type: mapping
+  translatable: true
+  # Integrate with the Configuration Translation module.
+  form_element_class: 'Drupal\text\FormElement\TextFormatWithSummary'
...
+    value:
+      type: text
+      label: 'Body'
+      translatable: true
+    summary:
+      type: string
+      label: 'Summary'
+      translatable: true
+    format:
+      type: string
+      label: 'Text format'
  • With the form_element_class key which is good, see hook_config_schema_info_alter below
  • format is not translatable as text_format
function hook_config_schema_info_alter(&$definitions) {
  // Enhance the text and date type definitions with classes to generate proper
  // form elements in ConfigTranslationFormBase. Other translatable types will
  // appear as a one line textfield.
  $definitions['text']['form_element_class'] = '\Drupal\config_translation\FormElement\Textarea';
  $definitions['date_format']['form_element_class'] = '\Drupal\config_translation\FormElement\DateFormat';
}
penyaskito’s picture

Status: Needs review » Needs work
+++ b/core/modules/config_translation/src/FormElement/TextFormat.php
@@ -27,14 +28,15 @@ public function getSourceElement(LanguageInterface $source_language, $source_con
-    return [
+    return NestedArray::mergeDeep(parent::getTranslationElement($translation_language, $source_config, $translation_config), [
...
-    ] + parent::getTranslationElement($translation_language, $source_config, $translation_config);

Should we respect the order here? I'm not sure if it's relevant in this case, but could hide bugs.
PHP arrays addition is not commutative (A+B != B+A).

I don't see why those css classes are needed now and not before, but being fair I didn't really test it.

+++ b/core/modules/text/config/schema/text.schema.yml
@@ -27,15 +27,8 @@ field.field_settings.text:
 field.value.text:
-  type: mapping
+  type: text_format
   label: 'Default value'
-  mapping:
-    value:
-      type: label
-      label: 'Value'
-    format:
-      type: string
-      label: 'Text format'

This is great!

jungle’s picture

+++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
@@ -1111,6 +1112,70 @@ public function testMenuTranslationWithoutChange() {
+   * Test translation of a default value of a text with summary field.

As it's being set back to NW, here should start with 'Tests', #3133162: Replace the start verb Test with Tests in method comments of tests

I've been trying to test it manually, but I can not get the same result as the test. Leaving this issue temporarily

Wim Leers’s picture

  1. +++ b/core/modules/text/config/schema/text.data_types.schema.yml
    @@ -0,0 +1,19 @@
    +# See the 'text_format' type in core.data_types.schema.yml.
    

    While we're making this consistent, we should move the text_format type out of core.data_types.schema.yml and into this file.

  2. +++ b/core/modules/text/src/FormElement/TextFormatWithSummary.php
    @@ -0,0 +1,41 @@
    +use Drupal\config_translation\FormElement\TextFormat;
    

    Let's move this class into the text module too while we're at it?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Sorry for taking so long to get back to this.

#39

Should we respect the order here? I'm not sure if it's relevant in this case, but could hide bugs.

that I'm not 100% about, may need a bigger brain then my own

Edit: As far as the classes go I believe they were copied from StringTextareWidget.php

#40 fixed

#41.1 moved
#41.2 moved

Moved to MR so hiding patches

smustgrave’s picture

Status: Needs work » Needs review

Reverted #41.1 as it caused some failures and may want to handle in a follow up.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

I agree we don't need to do #41.1 in this issue, it can be a followup for later. Can we file that already as a seperate issue? Otherwise this looks good to go imho.

longwave’s picture

Issue tags: +Needs followup

Tagging so we don't forget #41.

penyaskito’s picture

Issue tags: -Needs followup

Created #3395923: Move TextFormat form element from config_translation to text module
Created #3395927: Move text_format data type from core to text module

I think they are independent of each other. Removing "needs followup" tag.

longwave’s picture

Status: Reviewed & tested by the community » Needs review
smustgrave’s picture

Reverted the move.

penyaskito’s picture

Status: Needs review » Reviewed & tested by the community

We have split the bits that require BC layer into follow-ups. The fix itself was RTBC before, and I think it is, so setting it back to RTBC.

quietone’s picture

Status: Reviewed & tested by the community » Needs work

I'm triaging RTBC issues. I read the IS and the comments. I didn't find any unanswered questions or other work to do.

The diff does not apply to 11.x, there setting to NW for a rebase.

This may need a CR with a screenshot informing the user of this new capability.

ankithashetty made their first commit to this issue’s fork.

ankithashetty’s picture

Status: Needs work » Needs review

Rebased done, hence moving to NR.
Still need a update on CR as requested in #52.

Thanks!

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Restoring status after reroll.

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs manual testing, +Needs issue summary update
FileSize
29.79 KB

Always nice to see an old issue getting attention, thanks!

Comment #53 states that this is in need of a CR, therefor setting back to needs work.

To learn more about what this is fixing I tested on Drupal 11.x today, standard install, with a second language and a Textwithsummary field. I was able to translate the default value field without the patch here. Yet, the issue summary states that this change is to allow, "Default values of text fields can be translated using a text editor." Am I missing something? I don't work with translations so maybe I am.

I applied that patch and the translation modal was changed so that both the english default value and the translation default value can be edited. I don't think that it correct, only the translation should be editable. In fact the title is "Edit Italian translation for TextWithSummary" so it should only be for the Italian version.

It is not clear to me what is being fixed here. Tagging for an issue summary update. And since this is changing the UI it should have links to up to date before/after screenshots in the issue summary.

Looking back at the comments I do not see any manual testing. I am adding a tag for that.