Problem/Motivation
Layout Paragraphs Builder Experimental widget displays the original language (source) when editing a translation. This makes it impossible to translate or edit translated content from the frontend.
Steps to reproduce
- Install Drupal as multilingual system or use Umami
- Create a layout Paragraph type for layouts
- Create a paragraph type with a text field
- Configure the text field as translatable
- Create a new Content type with a Paragraph field and allow the use of the two Paragraph types created above
- Under Manage Display, use the Layout Paragraphs Builder Experimental widget
- Create a new content in any language
- Create a translation into another language and edit the paragraphs via frontend
- When editing, the original language is displayed
Issue fork layout_paragraphs-3305070
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:
Comments
Comment #2
j-leeI think that the problem was introduced with the release of v2.0. With beta9 the experimental widget still worked as expected.
Comment #3
j-leeComment #6
j-leeThank you for the merge request. Works well for us.
Comment #7
justin2pin commentedComment #8
Nowrie commentedHi all,
I'm working on a project with Drupal 9.4 where I'm using layout paragraphs 2.0.1 with the experimental widget. As stated in this issue, whenever I translate an entity, the process is correct. However, editing the paragraphs on the translated entity also changes the values in the untranslated entity.
Not sure if this is because the rendered form is not the correct one, or because the paragraphs aren't being translated so it just renders always the untranslated ones.
Are there any temporary solutions until this patch is applied to the main version? I've tried recreating the code on the pull request but I failed in doing so.
Any help would be very much appreciated as I'm really stuck with this.
Kind regards,
Ismael.
Comment #9
j-lee@Nowrie can you check it in conjunction with the patch from #3259729?
It can also be a problem with the multilingual setup.
Comment #10
finex commented@j-lee: hi, I've tried to manually apply your patch to the current -dev version (without patch from #3259729).
The concept looks fine: now the experimental widget use the correct language. But the save/close/cancel buttons doesn't work anymore.
Did the buttons work on your branch?
Thank you very much!
Comment #11
j-lee@FiNeX: Sorry for the late response. Yes, everything works with this MR in combination with #3259729 on our multilingual setup.
For the latest release we need a rebase for the current MR.
But I am very busy at the moment ...
Comment #12
socialnicheguru commentedpatch no longer applies
Comment #14
cobadger commentedUpdated patch attached.
Comment #15
stmh commentedThe patch from #14 works as advertised, but not 100% correct, at least for my scenario. Say I have 2 languages en and de. I create content in en and add a translation for de. Editing the translation works as expected, but the preview shows then the english page. Reloading the page shows then the updated content in the correct language.
Comment #16
joachim commentedUnrelated change.
Unrelated, and incorrect change - elses should not be coddled.
Comment #17
joachim commentedComment #18
joachim commentedSurprisingly, the MR's branch (which is currently hidden) *doesn't* have the problem described in #15, the incorrect return to the default language when working with a translation.
However, that currently conflicts with the 2.0.x branch and needs a rebase.
(BTW it gets confusing when an issue has BOTH a MR and patches!)
Comment #19
joachim commentedTrying to rebase the branch...
Comment #20
j-leeI think justin2pin closed the MR because of the many changes since the MR was created. That is why the MR is out of date.
The patch from #14 changes the field values to the translated values. But the field with the source language is inserted into the LayoutParagraphsLayout (Line 129 in patched Drupal\layout_paragraphs\Form\LayoutParagraphsBuilderForm) which is used to create the tempstore key. If the field language is changed, the correct language will be displayed in the UI after saving the changes.
Comment #21
joachim commentedDoes anyone know why the MR removes this code from LayoutParagraphsBuilderForm::submitForm():
Comment #22
j-leeMaybe because the entity is cloned at buildEntity()?
Comment #23
joachim commentedFiled #3352152: Get the request time to set on the updated entity in LayoutParagraphsBuilderForm for the use of the time service which is in the MR here, and unrelated to this issue.
Comment #24
joachim commentedThis code (and related changes) probably also needs moving to a separate issue:
EDIT On second thoughts, I don't know -- nothing in the MR call this method!!! And I don't understand whether the intention is that a new revision is created for the parent entity or the paragraph!
Comment #25
joachim commentedThanks for the feedback @J-Lee.
You're right, the MR is really out of date.
Also, it's trying to fix the problem by removing the use of the custom form element, which surely isn't right:
If the custom form element is showing the wrong language, it needs to be fixed, not bypassed!
Things in the patch don't look right either though:
$entity is already in the correct language at this point, because it's loaded by the routing system which takes into account the current language.
Setting the paragraph BACK into the entity looks really wrong!!!
I've tried your suggested fix for the patch:
It doesn't work - when I click the Save button, I see the original language for the paragraph and not the translation.
I'm not sure about doing that to the $field anyway -- it's an entity reference field, so it won't be set to translatable.
Comment #26
joachim commentedI think we need to add the $entity as a constructor parameter to LayoutParagraphsLayout:
I don't think we can get the right language from what it currently receives.
We get $entity->activeLangcode set to the translation language, but $entity->FIELD->parent->entity->activeLangcode is set to the **default language**. So we can't get hold of the correct language to use.
Comment #27
j-lee@joachim You are right. It doesn't seem to be possible to get the currently used language from the field.
Either the entity must be specified or the language, which in turn would have to be taken into account in LayoutParagraphsLayout.
Comment #28
j-leeIn the LayoutParagraphsLayout class, there is a getEntity() method that gets the entity from the entity reference field, but there is also a setEntity() method that sets the entity dynamically and is not used. This looks a bit strange. Maybe this is the point where you could start.
Comment #30
joachim commentedI've got this working!
Thanks for your help @J-Lee!
Work is on a new branch '3305070-set-language-on-layout' with a new MR.
Comment #31
j-leeLooks good. Thank you.
Comment #32
j-leeAh, there are still the tests missing ... back to needs work.
Comment #33
grumpydev74@joachim, @J-Lee thank you guys, you are life savers on that issue !
The patch works !
Hope the MR will be approved and released in the next module's version.
Edited :
Actually there is still an issue dealing with multi languages using the experimental widget :
1- use the widget to add a paragraph on the main site's language
2- save the page
3- got to another language version of the page
4- click the "Edit components" button
5- you will receive the following error:
Comment #34
j-leeI can confirm the problem and have left a comment at the appropriate place in MR. With
$entity->hasTranslation($this->langcode)and$entity->addTranslation($this->langcode)we can solve this.Comment #35
grumpydev74Thank you again @J-Lee.
Another issue remains however. When clicking the "Save button" at the bottom of the layout paragraph builder interface (to save paragraphs items order) the page is reloaded and paragraphs are displayed using the default language like described in the comment #15. Then if you click the "Close button", the paragraphs are back in the correct language. I don't know if it is linked with your proposed solution in the MR, but it would avoid confusion for editors and need to be fixed too.
Comment #36
cobadger commented@jleehr thanks so much for the suggested changes to MR122. I included them in a patch file and tested locally.
My experience was that the error that @grumpy74 described did not appear, so that's great.
However, in my testing the new paragraph that I added on the site's main language did not show up when I edited the page in an alternate language.
I'd be curious to hear whether others experience the same thing using patch 36.
Comment #37
grumpydev74@COBadger thank you for the provided patch. I tested it and it seems to fix the issue with the language code I was pointed out.
However. There is still another problem remaining.
Reproduce the steps described in my comment #33.
Then, when you have a node with paragraphs created and you have already the translated node created afterward, the paragraphs exist on the translated node too. But as soon as you re-edit the default language node paragraphs to add new one for example, here comes the issue.
Basicaly at that point the default language has a new paragraph added to the items list, but the translated node do not have that reference yet. So if you go to the translated node front page you see the newly added paragraph in the widget preview (which is correct), but as soon as you click "Edit components", the display switch to the edit display and the paragraph disappears (because actually the paragraph translation do not exists). I think when the widget switch to edit mode, the same kind of test on the paragraph translation existence must be done. Like if the paragraph do not exists for the translation language, in edit mode, we must create a new paragraph translation when clicking "edit" icon to be able to add the translation instance of the paragraph to the translated node.
On the other hand (and it is not part of that specific issue), the widget should not propose the controls "add", "duplicate" or "delete" on a non default language entity, as this is forbidden by design by the paragraphs principles (paragraphs are ISO between languages).
I hope my description is clear enough for the context overall understanding.
On my side for instance, I took the decision to write custom code to force node translation creation and paragraphs translation creation on node post save to avoid that issue (which is not ideal, but it fits my needs so far), but it should be handle by the widget IMHO.
Hope this will help resolving the issue. I'm sorry to not contribute actively on the code part of this, but I can help by testing patches.
Comment #38
joachim commentedI'm not managing to reproduce the error described in #33.
I tried both with a node that didn't have a translation, and one which did.
Please could we stick to the MR and not also make patches? It's going to get really confusing if we have both MRs and patches floating around.
Comment #39
j-leeWe have tested it again. Now we could not reproduce the problem from #33.
We only used the changes from MR, not the patch from #36 with my previously suggested changes.
We should definitely have tests for that.
I agree, we should use the MR. I think COBadger makes the patch just to test my suggestions.
Comment #40
j-leeJust as a note, we also tested the MR in conjunction with #3259729: Fatal error saving translation when content moderation is enabled in a development environment. Maybe this fixes some of the other translation issues as well?
Comment #41
joachim commentedI'm working on tests :)
Comment #42
joachim commentedAdded test.
Comment #43
cobadger commentedChanging status back to "Needs work".
In my test of the merge request I took the following steps:
With the logic from my comment on the merge request when I performed the above steps I did see the new paragraph in the layout editor, and it saved as expected.
Comment #44
joachim commented> 4. Observed that the new paragraph from Step 1 above did not render in the layout editor as expected
Do you mean that the new paragraph *should* appear there?
Comment #45
j-leeStrange that sometimes my suggestion is needed and sometimes not. Maybe it is due to different language settings?
To make the codebase more robust, I would suggest to apply the check to the language/translation.
Comment #46
cobadger commentedAs the tests have passed I'm marking this RBTC.
Comment #47
joachim commentedThanks for the fix.
However, people who've worked on the MR shouldn't set it to RTBC - that should be done by reviewers.
Comment #48
j-leeThe nit-pick could be done on commit.
Thank you all for the work.
Comment #49
justin2pin commentedThanks for all the work on this. Unfortunately, I think this needs a little more work. I don't think we want to add translation functionality directly into the LayoutParagraphsLayout class, as it assumes a little too much about possible use cases. Specifically, I'm concerned that this does not accommodate asymmetric paragraph translations.
So... I think we need to keep functionality specific to translations in the widget / formatter, and not in the underlying API classes. It might be worth abstracting the translation functionality into either a service or trait that both the widget and formatter can use, or refactoring the formatter so it just invokes the widget -- rather than directly using the layout paragraphs builder render element.
Comment #51
prompt-h commentedWe're currently sticking with version 2.0.0-beta9 for this module due to its compatibility with multi-language websites. Newer versions of the module aren't suitable for such websites. Any help would be appreciated.
Comment #52
ytsurkI'm using the module's version 2.0.4 with this MR's patch (https://git.drupalcode.org/project/layout_paragraphs/-/merge_requests/12...) for symmetric paragraph translation.
This module forces you to use go with asymmetric translation, which is not official supported (nor recommended) by the paragraphs module itself.
If you can explain the incompatibility issues you have, we can try to guide you?
Comment #53
prompt-h commentedWe were able to update to 2.0.4 on several multi-language websites and use async translation successfully with the provided patch. Thank you!!
Comment #55
j-leeComment #57
j-leeOpened MR 191 which has the same status as MR 122, but has been rebased to version 2.1.x.
Comment #58
j-leeStill needs work, see comment by justin2pin #3305070-49: Experimental widget displays the original language on translation
Comment #59
j-leeAnd a patch file for 2.1.x
Comment #60
kristiaanvandeneyndeTrying to combine this MR with the one from #3269138: Support revisions and content moderation with the Layout Paragraphs Builder Field Formatter as both deal with the same part of the widget that needs some love. I noticed a discrepancy in how one method has a fail-safe for missing translations and the other does not. Will fix in the combined patch that I'm working on to see if it holds up.
Comment #61
spfaffly commentedRe-rolled patch for 2.2.x
Comment #62
kanchamk commentedI am facing the same issue and tested all the patches provided in this issue, but none of them resolved my problem.
Environment:
Steps to reproduce:
entity_reference_revisions), including nested paragraphs and media fields, make nested paragraph fields as translatableActual result:
The DE translation content is overwritten with the updated EN paragraph values.
Expected result:
Saving or updating the default language (EN) should not override paragraph or nested paragraph content in other translations. Each translation should retain its own independent paragraph field values.
Edited:
Ignore it, it is working fine after some configuration changes.
Comment #63
kanchamk commentedComment #64
kanchamk commented