Problem/Motivation

Steps to reproduce:

  1. Add the Italian language
  2. Enable content translation and content moderation for articles
  3. Configure one field as being untranslatable
  4. Create an English published article
  5. Create an Italian published translation
  6. Save some changes to the Italian translation as draft
  7. Edit the English translation and save after changing the untranslatable field
  8. Edit the Italian translation

Expected result: the Italian draft field values are loaded
Actual result: the Italian published field values are loaded

Proposed resolution

Always hide untranslatable field widgets on translation forms, when content moderation is enabled. This is not ideal, but it should be acceptable, since this was already the recommended mode when enabling CM. The other mode is available mainly to retain BC with workflows not relying on pending revisions.

Remaining tasks

  • Validate the proposed solution
  • Write a patch
  • Reviews

User interface changes

API changes

None

Data model changes

None

Comments

plach created an issue. See original summary.

plach’s picture

Here's a fix, tests coming soon.

plach’s picture

Status: Active » Needs review
plach’s picture

Issue tags: -Needs tests
StatusFileSize
new10.13 KB

Here's a test only patch.

plach’s picture

StatusFileSize
new18.34 KB

And here's the full patch.

plach’s picture

Issue summary: View changes

The last submitted patch, 4: ct-ut_field_hide-2949710-4.test.patch, failed testing. View results

plach’s picture

Assigned: plach » Unassigned
plach’s picture

Issue summary: View changes
StatusFileSize
new900 bytes
new18.34 KB
new87.39 KB

Gábor suggested that there should be an explanation on the UI when the checkbox is disabled. Screenshot updated.

plach’s picture

StatusFileSize
new18.45 KB

Sorry, the interdiff was correct, but the patch was the wrong one.

plach’s picture

(hidden outdated files)

plach’s picture

Issue summary: View changes
StatusFileSize
new1.03 KB
new18.49 KB
new88.94 KB

@catch suggested a wording improvement in Slack

catch’s picture

The approach here makes sense to me, I never understood how untranslatable fields could work with draft revisions and this essentially stops us having to worry any more.

One nit:

+++ b/core/modules/content_translation/src/ContentTranslationManager.php
@@ -158,8 +164,32 @@ protected function loadContentLanguageSettings($entity_type_id, $bundle) {
+    }
+
+    $result = FALSE;
+    foreach (Workflow::loadMultipleByType('content_moderation') as $workflow) {
+      /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration $plugin */
+      $plugin = $workflow->getTypePlugin();
+      $entity_type_ids = array_flip($plugin->getEntityTypes());
+      if (isset($entity_type_ids[$entity_type_id])) {
+        if (!isset($bundle_id)) {
+          $result = TRUE;
+          break;
+        }
+        else {
+          $bundle_ids = array_flip($plugin->getBundlesForEntityType($entity_type_id));
+          if (isset($bundle_ids[$bundle_id])) {
+            $result = TRUE;
+            break;
+          }
+        }
+      }
+    }

I think two early return TRUE; instead of the assignment might make this more readable, with just return FALSE at the end.

plach’s picture

StatusFileSize
new18.42 KB
new1.23 KB
catch’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#2942907: Entity system does not provide an API for retrieving an entity variant that is safe for editing

Apart from the workaround this is a straightforward change, and we have an issue open to add the API that would allow us to remove the workaround at #2942907: Entity system does not provide an API for retrieving an entity variant that is safe for editing (or possibly a further follow-up to that issue).

Moving to RTBC.

effulgentsia’s picture

Adding reviewer credit.

  • effulgentsia committed 5fd1186 on 8.6.x
    Issue #2949710 by plach, catch: Pending revisions may become unavailable...

  • effulgentsia committed 809d71b on 8.5.x
    Issue #2949710 by plach, catch: Pending revisions may become unavailable...
effulgentsia’s picture

Version: 8.6.x-dev » 8.5.x-dev
Status: Reviewed & tested by the community » Fixed

The approach here makes sense to me, I never understood how untranslatable fields could work with draft revisions and this essentially stops us having to worry any more.

I disagree. #2878556: Ensure that changes to untranslatable fields affect only one translation in pending revisions already solved the problem of changing UT fields in pending revisions. That issue introduced constraints to disallow that. This issue isn't about that: the s.t.r. only involve changing translatable fields in a pending revision, and UT fields in a default revision. At least in theory, that should be possible to work as expected without forcing the "Hide non translatable fields on translation forms" checkbox. However, given that this Critical bug exists with that checkbox off, I agree with implementing this patch as a stop-gap until having that checkbox unchecked can be made to work correctly without this data integrity bug.

Therefore, pushed to 8.6.x and 8.5.x.

Status: Fixed » Closed (fixed)

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