Problem/Motivation

When we enable translation for a content type with a not translatable (no translation enabled) paragraphs field, we create a node and attempt to translate it, we get a error like:

Field content_translation_source is unknown.

Proposed resolution

Fix it.
Write tests.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yongt9412 created an issue. See original summary.

miro_dietiker’s picture

Issue tags: +Needs tests

I don't get the description...
It sounds like i would always trigger this condition when doing multilingual setup?

Step by step please...
(A test? And a fix? ;-) )

johnchque’s picture

Issue summary: View changes
johnchque’s picture

Discussed with @Berdir this fix should be enough, the paragraph that is displayed on translation is the one available for all languages. :)

The last submitted patch, 4: paragraph_with_no-2761493-4-test-only.patch, failed testing.

The last submitted patch, 4: paragraph_with_no-2761493-4-test-only.patch, failed testing.

The last submitted patch, 4: paragraph_with_no-2761493-4-test-only.patch, failed testing.

Berdir’s picture

Status: Needs review » Needs work
+++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
@@ -240,14 +240,21 @@ class InlineParagraphsWidget extends WidgetBase {
+        // If translation is not enabled for paragraphs field do not switch.
+        if ($paragraphs_entity->hasField('content_translation_source')) {
+          // Switch the paragraph to the translation.
+          $paragraphs_entity = $paragraphs_entity->getTranslation($langcode);
         }

The comment isn't correct, that's not what it is doing.

The source field is a base field. It is added if at least one paragraph type is translatable. But it existing doesn't mean that the paragraph type that you have is actually translatable. And it's even less about the paragraph field.

As quickly discussed, the question is, what should we do if the paragraph type is indeed not translatable? Maybe not show the paragraph at all. Or show a message that paragraph type X is not translatable? I'm not sure..

I'd also be ok with saying we just prevent the error for now and figure that out later. But then we need a better comment and I think we should have a single wrapping if() around the whole multilingual thingies. And maybe an "All languages" suffix on the label, like core has for shared fields?

johnchque’s picture

Manually testing, when a paragraph is not translatable it is always displayed with a (all languages), actually IMHO it makes sense to displayed and the if added works fine in that way.

The last submitted patch, 9: paragraph_with_no-2761493-9-test-only.patch, failed testing.

The last submitted patch, 9: paragraph_with_no-2761493-9-test-only.patch, failed testing.

The last submitted patch, 9: paragraph_with_no-2761493-9-test-only.patch, failed testing.

miro_dietiker’s picture

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

Improved some comments and committed. :-)

Still back to needs work to create follow-ups about the workflow in the situation. We need to decide what experience is the goal.

miro_dietiker’s picture

Sry, accidentally committed with reference and message to #2755897: Cannot use paragraphs within Contact form

Berdir’s picture

Status: Needs work » Fixed

I have a feeling those follow-ups aren't going to be created if it didn't happen in the last two years and we likely fixed the problems we identified or there are open issues about it.

Status: Fixed » Closed (fixed)

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