Problem/Motivation

Layout Builder does not support translated layout overrides currently. Any new sites installing Layout Builder will not be able to enable translation on Layout field through Content Translation.

But some sites that had both content translations and Layout Builder enabled before #3041659: Remove the layout tab from translations because Layout Builder does not support translations yet and had both translations and layout overrides on the same bundles maybe have Translations still enabled on the Layout field.

It could be not safe for them to just turn off translations because they may need the current values they have in the translated fields.

Proposed resolution

On Content Translation admin form add a warning to all Layout fields with a link to the handbook page https://www.drupal.org/docs/8/core/modules/layout-builder/layout-builder...

Only sites that were installed when Layout Builder was still beta will see this warning.

Remaining tasks

None

User interface changes

@see Proposed resolution

API changes

None

Data model changes

None

Release notes snippet

CommentFileSizeAuthor
#28 3043646-28.patch3.88 KBtedbow
#28 interdiff-24-28.txt1.58 KBtedbow
#24 3043646-24.patch3.76 KBtedbow
#24 interdiff-20-24.patch7.42 KBtedbow
#20 Screen Shot 2019-03-28 at 10.21.39.png29.67 KBlauriii
#20 interdiff.txt510 byteslauriii
#20 3043646-20.patch6.14 KBlauriii
#19 interdiff.txt2.7 KBlauriii
#19 3043646-19.patch6.14 KBlauriii
#17 interdiff-16-17.txt3.08 KBtedbow
#17 3043646-17.patch6.16 KBtedbow
#17 with_icon.png34.19 KBtedbow
#16 description_with_changes_content_moderation.png90.08 KBtedbow
#16 use_description.png43.91 KBtedbow
#16 3043646-use_description-16.patch4.53 KBtedbow
#16 3043646-use_description-simple16.patch3.15 KBtedbow
#15 3043646-plain_text_no_links.patch3.87 KBtedbow
#15 3043646-render_arrays_are_the_best.patch3.38 KBtedbow
#15 render_array_from___oh_please_nooooo.png64.46 KBtedbow
#14 Content_language___Site-Install.png27.41 KBxjm
#12 3043646-11.patch5.64 KBbnjmnm
#9 Ceçi__c_est_en_français___Site-Install.png1.27 MBxjm
#9 Ceçi_n'est_pas_en_français___Site-Install-2.png635.87 KBxjm
#9 AMERICA_AMERICA_AMERICA___Site-Install.png736.11 KBxjm
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett created an issue. See original summary.

xjm’s picture

We have a few options:

  • Alter in a confirmation form when the user enables translation for an LB field. E.g. "Translating layouts is not currently supported and enabling translation on this field may have unintended consequences." Or something.
  • Display a DM on the content translation configuration page for the same.
  • Add a status report notice similar to the JSON:API one if the user has this field translation enabled (possibly with additional warning if the field actually contains data). @webchick was -1 on this but I think it merits discussion.
xjm’s picture

Title: For sites that have made layout overrides prior to 8.7.0, add UI warnings about the translatability of the layout field » For sites that have made layout overrides prior to 8.7.0 or sites that manually enable translation of the layout override field, add UI warnings

I think this also applies to sites that might try turning this on in the future, since we're not disallowing it, only changing the default. I'd want those sites to see a warning that says "Enabling translation of this field won't do what you think it's going to."

tim.plunkett’s picture

Are you saying we have to care about sites that *manually edit their config* to bypass the changes in our new patch?

effulgentsia’s picture

I think this also applies to sites that might try turning this on in the future, since we're not disallowing it, only changing the default.

For entity types with no existing bundles using layout overrides, we're able to set it to untranslatable at the $field_storage level, which means it's not shown in the CT config form at all. No checkbox to enable, so no way to "try turning it on". Per #4, they'd have to do a config export, manually edit the YAML, then import those manual changes. I don't think we should cater to that.

But, for entity types with existing bundles using layout overrides, when layout overrides are added to a new bundle, we can only set that to untranslatable at the $field level, and therefore, that does show up in the CT config form as a checkbox that's unchecked but can be checked.

xjm’s picture

Right, it's the second part of #5 I'm concerned about. Any site that has overrides is like a carrier of a disease for this problem, even if they don't use Content Translation already.

xjm’s picture

@effulgentsia Maybe you could add STR to the IS showing the problem in that case? I think it's something like:

  1. Install 8.6. Enable Builder but not Content Translation.
  2. Enable layout overrides for articles.
  3. Update to 8.7. Merrily going along adding layout overrides because LB is a great tool! You don't know anything is wrong.
  4. A year from now, when any release notes or CRs from 8.7 are long forgotten, enable Content Translation, because you're getting enough business that the CEO says you should add English version of the content.
  5. Install a second language at admin/config/regional/language.
  6. Enable translation for node content at /admin/config/regional/content-language.
  7. Mark Articles as translatable. Note that the translation checkbox for Layout is checked by default.
  8. Click "Save" because you have no way of knowing there's anything wrong with the defaults you just enabled.
xjm’s picture

I'm going from this in the CR:

For sites that enable Content Translation at a later time
Sites that had layout overrides enabled before 8.7.0 and some time later enable the Content Translation module should follow the steps above to set the layout field to non-translatable.

xjm’s picture

Here's another scenario I'm concerned about:

(Advance apologies to all the francophones for the typo in "ceci" in the screenshots.)

  1. Check out f1e6647a323 or anything earlier on 8.7.x. EDIT: Per @tedbow, the following scenario is the behavior of only 8.7.x sites, not 8.6.x ones.
  2. Install Standard, Layout Builder, Content Translation
  3. Install French (or your language of choice) at /admin/config/regional/language
  4. Enable translation of content on /admin/config/regional/content-language
  5. Enable layout overrides for articles at /admin/structure/types/manage/article/display
  6. Create an article entitled "AMERICA YEAHHHHHH" at node/1.
  7. Go to /node/1/layout. This article is so American that a stars-and-stripes eagle should be eating apple pie in a baseball diamond, so add a custom block with an appropriate image. Save the layout.
  8. Now go to /fr/node/1/translations/add/en/fr and try to take things down a notch. Translate and save.
  9. Notice the giant American flag at the top of your content. Irritatedly click the layout tab on your page to fix the problem.
  10. Delete the "YEAHH AMERICA YEAHHH" block and replace with a nice painting of Notre-Dame.
  11. Save. That's much better, right?
  12. Switch back and forth between the two, editing their layouts. Everything seems to be working fine. You can edit either, and neither updates the other. I tested this over and over and could not reproduce the problem of one overwriting the other.
  13. Update to 8.7.x HEAD and clear the cache. Try to edit the French layout. It's stuck there, as-is, forever. There's no information in the UI indicating how to change it. There's nothing on your status report about why this happened. I'm just a content translator; I don't know anything about Drupal updates and it might be months before this problem is actually discovered.

Should a message be put on this page? Status report message about this orphaned layout content? What?

Edit: This particular scenario affects only sites updating from (e.g.) 8.7.0-alpha1 to 8.7.0-beta1, so we'll want to differentiate between the two for the release note. I'll update the original issue accordingly.

xjm’s picture

@tedbow clarified that the regression in #9 is specific to 8.7.x sites. I'll test from 8.6.x next.

bnjmnm’s picture

An issue similar to this is addressed in Paragraphs.
Fields of the type Paragraph are non-translatable, but are enabled by default in content translation, so they also need to inform the user that the field is not actually translatable.

A screenshot of the approach can be seen here #2760341: Let the user be aware that Paragraphs fields are not supported for translation
The "(* unsupported) Paragraphs fields do not support translation" message is always present at the top of the Content Translation form. The message is formatted as a warning unless a field of the type Paragraph is set as translatable, in which case it is formatted as an error.

Adding a message to the top of the Content Translation form + appending a warning to the field names seems like it would work here as well, and it would match a pattern that has likely been seen by many users already. I'd prefer if there was some kind of form validation involved so it wasn't even possible to enable translation for the field, but the fact that this validation wasn't implemented for Paragraphs suggests that there were implementation barriers or other good reasons for not including it.

Also note there has been interest in improving this experience in Paragraphs, but it has proven difficult to implement: #2787095: Improvements for translation settings

bnjmnm’s picture

This is an implementation of how it is approached in Paragraphs. The specifics of the solution for this haven't been fully hashed out yet, but this should be fairly easy to build from. Hopefully any additional changes just require changing the form_alter that is provided here.

tim.plunkett’s picture

Status: Active » Needs review
xjm’s picture

Issue summary: View changes
Status: Needs review » Needs work
FileSize
27.41 KB

Discussed with @dyannenova with @webchick. We've compromised on something like this:

(With the yellow triangle warning icon in place of [!].)

tedbow’s picture

@xjm thanks for posting the image.

Here the 2 options neither is good. Neither is done but wanted to get feedback.

Render array fun

So putting actual html and not plaintext in with the label is very difficult because of what _content_translation_preprocess_language_content_settings_table() it move the different # properties of the form around and puts #label in a #plain_text element and then within that section the $build there is nothing that actually gives us the machine of the field and the input is already rendered so we can't even find it from that

Please observe
render array

So we at least have to make a 1 line change to _content_translation_preprocess_language_content_settings_table() to set the field name to tell which element we need to alter.

here is solution in that manner it is not finished but I would like feedback if this is the way we want to go.

The plain text option

We could just use hook_form_FORM_ID_alter to add a warning to the label but that gets set to #plain_text in _content_translation_preprocess_language_content_settings_table() so we can't have a link.

tedbow’s picture

Here is what I think is better option. Actually using the #description property of the checkbox but then changing _content_translation_preprocess_language_content_settings_table to actually moving it which it should be doing anyways.
form with changes to content moderation

I will also add another patch that simply sets #description and then moving it in _content_translation_preprocess_language_content_settings_table could be a follow up.
form with no changes to content moderation

Basically I feel this last way is correct. But it looks bad because _content_translation_preprocess_language_content_settings_table does take into account that these form elements could have #description

tedbow’s picture

Had to add a whole new library to get the css for this

interdiff is of 3043646-use_description-16.patch

tim.plunkett’s picture

+++ b/core/modules/layout_builder/layout_builder.module
@@ -367,3 +387,24 @@ function layout_builder_entity_translation_create(EntityInterface $translation)
+        $layout_field_checkbox['#description'] = t('<strong>Warning</strong>: Layout Builder does not support translating layouts. (<a href="https://www.drupal.org/project/drupal/issues/3041659" >online documentation</a>.');

Weird space at the end of the A tag and you are missing a closing parentheses within the string

Otherwise, it looks like it's supposed to!

lauriii’s picture

Moved the icon a few pixels down to align with the text in Seven. I also converted the description class to use BEM and fixed #18.

lauriii’s picture

Oops. I was in a bit hurry and accidentally forgot to update the value from Chrome debug tools to the patch.

Here's how this looks now:

webchick’s picture

That's more or less the spec that @DyanneNova came up with, so looks good.

The last submitted patch, 19: 3043646-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

The last submitted patch, 16: 3043646-use_description-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

tedbow’s picture

Ok chatted with @effulgentsia and @tim.plunkett.
We figure out a way to

  1. limit our change our change to content_moderation to 1 line
  2. remove the need for our hook_form_alter

Yay for small patches! thanks all!

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community
  1. +++ b/core/modules/content_translation/content_translation.admin.inc
    @@ -255,6 +255,7 @@ function _content_translation_preprocess_language_content_settings_table(&$varia
    +        '#field_name' => $field_name,
    
    +++ b/core/modules/layout_builder/layout_builder.module
    @@ -367,3 +367,46 @@ function layout_builder_entity_translation_create(EntityInterface $translation)
    +    if (isset($row['#field_name']) && $row['#field_name'] === OverridesSectionStorage::FIELD_NAME) {
    

    This small addition to CT goes a long way!

  2. +++ b/core/modules/layout_builder/layout_builder.module
    @@ -367,3 +367,46 @@ function layout_builder_entity_translation_create(EntityInterface $translation)
    +function layout_builder_theme_registry_alter(&$theme_registry) {
    +  // Move our preprocess to run after
    +  // content_translation_preprocess_language_content_settings_table().
    +  if (!empty($theme_registry['language_content_settings_table']['preprocess functions'])) {
    +    $preprocess_functions = &$theme_registry['language_content_settings_table']['preprocess functions'];
    +    $index = array_search('layout_builder_preprocess_language_content_settings_table', $preprocess_functions);
    +    if ($index !== FALSE) {
    +      unset($preprocess_functions[$index]);
    +      $preprocess_functions[] = 'layout_builder_preprocess_language_content_settings_table';
    +    }
    +  }
    +}
    

    While complex, this is a standard hook_theme_registry_alter implementation

Thanks everyone!

effulgentsia’s picture

All the PHP code, including the 1 line addition to content_translation, looks great to me.

Leaving the final review for a frontend framework manager.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs frontend framework manager review
+++ b/core/modules/layout_builder/css/layout-builder-content-translation.css
@@ -0,0 +1,4 @@
+.layout-builder-translation-warning {
+  background: left 2px url(../../../misc/icons/e29700/warning.svg) no-repeat;
+  padding-left: 20px;
+}

This change looks great for me overall. This CSS is Seven specific. We should add a todo comment here to remember to move this to Seven as part of #3041053: Mark Layout Builder as a stable module.

tedbow’s picture

Status: Needs work » Needs review
FileSize
1.58 KB
3.88 KB
tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

+1

tedbow’s picture

Issue summary: View changes
tedbow’s picture

Issue summary: View changes

larowlan’s picture

  • larowlan committed a83655a on 8.8.x
    Issue #3043646 by tedbow, lauriii, bnjmnm, xjm, tim.plunkett,...

  • larowlan committed 7f5a4bc on 8.7.x
    Issue #3043646 by tedbow, lauriii, bnjmnm, xjm, tim.plunkett,...
larowlan’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Reviewed & tested by the community » Fixed

Committed a83655a and pushed to 8.8.x. Thanks!

C/p as 7f5a4bc450 and pushed to 8.7.x

effulgentsia’s picture

+++ b/core/modules/layout_builder/layout_builder.module
@@ -367,3 +367,46 @@ function layout_builder_entity_translation_create(EntityInterface $translation)
+  // Move our preprocess to run after
+  // content_translation_preprocess_language_content_settings_table().
+  if (!empty($theme_registry['language_content_settings_table']['preprocess functions'])) {
+    $preprocess_functions = &$theme_registry['language_content_settings_table']['preprocess functions'];
+    $index = array_search('layout_builder_preprocess_language_content_settings_table', $preprocess_functions);
+    if ($index !== FALSE) {
+      unset($preprocess_functions[$index]);
+      $preprocess_functions[] = 'layout_builder_preprocess_language_content_settings_table';
+    }
+  }

So this doesn't just move it to after content_translation_preprocess_language_content_settings_table(), it moves it all the way to the end, including after theme preprocess functions. I think that's fine. I doubt there's any admin themes preprocessing this table in a way that would fail if the LB function comes after them. But, for anyone interested in there being an API for inserting things into desired positions of an array, there's #66183: Add helper methods to inject items into a particular position in associative arrays and possibly other similar issues.

lauriii’s picture

effulgentsia’s picture

Issue tags: +Needs followup

This patch was committed without a test. Which is fine, given the rush to get it in before beta. However, since it relies on the order in which preprocess functions run and internal details about another module's render array structure, and we may want to refactor it in 8.8.x to something more along the lines of #16, I think it could benefit from a test. Perhaps adding an extra assertion at the end of MakeLayoutUntranslatableUpdatePathTestBase::testDisableTranslationOnLayouts() for whether the warning appears on the form when we expect it to, and doesn't when we don't?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.