Steps to reproduce:
1. Create new entity browser for media entity bundles with images type provider
2. Add Entity reference field to the translatable node type
3. Select Entity browser widget for entity reference field and attach created entity browser
4. Create new content and upload image via Entity browser field, specify alt and title attributes for image
5. Add translation for created content
6. Try to overwrite entity browser's image attributes to new language (create translation for referenced media entity)
As result, it does not create new translation for referenced media entity
UPD:
Fast Fix PR:
https://github.com/drupal-media/entity_browser/pull/150
Comments
Comment #2
Oleks Iv CreditAttribution: Oleks Iv commentedComment #3
Oleks Iv CreditAttribution: Oleks Iv commentedComment #4
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedTest would be nice.
Comment #5
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedComment #6
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedComment #7
Leksat CreditAttribution: Leksat at Amazee Labs commentedA bit improved version of PR 150.
Comment #8
samuel.mortensonI'll work on tests.
Comment #9
samuel.mortensonI was looking through the code again and the patch seems very manual - I can't find examples of another Controller delivering an Entity Form and handling Translation this way. Has this issue been tested with any entity type other than Media Entities?
I ask this because forms like ContentEntityForm seem to do similar logic, which makes sense as the Entity Form in question here should be responsible for delivering the correct translation of an Entity - not Entity Browser. See ContentEntityForm::init() for what I'm referencing.
Comment #10
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedWhat about passing language via URL argument?
Comment #11
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedComment #12
blazey CreditAttribution: blazey at Amazee Labs commentedPatch no longer applies. Attaching rerolled version.
Comment #13
blazey CreditAttribution: blazey at Amazee Labs commented@samuel.mortenson Attaching a new, refactored version that takes your comments into account. Thanks to
$form_state->set('langcode', $langcode);
ContentEntityForm::init()
takes over translation handling. It doesn't copy values from source entity when adding translation though, so the following part has been added to improve UX:Comment #14
badrange CreditAttribution: badrange at Digia commentedJust tested adding this patch to my site under development and it did indeed fix the issue. Thanks.
Comment #15
samuel.mortenson@blazey Thanks! This patch is starting to look better.
So
ContentEntityForm::init()
already adds a translation, but as you mentioned does not copy values from the existing Entity. Can you explain the why using our own$entity->addTranslation
call is necessary here? What behavior is different with/without that call? I'm also wondering if there's an example of a controller doing this in core, since I would expect ContentEntityForm to handle all of this.Comment #16
blazey CreditAttribution: blazey at Amazee Labs commented@samuel.mortenson Thanks for review!
Without the call to
$entity->addTranslation
media translation form is displayed blank. Initial field values are not copied from the translation source. IMHO it's very inconvenient to select the same file every time you add a translation. There are definitely cases when you have to do that anyway (like when it's a pdf in different language) but often you just want to translate alt and title of the image and it's just easier (and more intuitive) to have the values (including the original file) prefilled.I have no idea why
ContentEntityForm
creates the translation but doesn't pass field values. It would be enough to change line 171 here http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Entity/Conte... fromto
Maybe it deserves a core issue? Anyway, for the time being it might be worth adding the translation ourselves as the UX gain is huge.
Comment #17
samuel.mortenson@blazey You mention media translation specifically - as Entity Browser can be used with any Entity Type, would copying values to the new translation make sense for Nodes as well?
Comment #18
blazey CreditAttribution: blazey at Amazee Labs commented@samuel.mortenson To me it would make sense as I would like to know what I'm translating. The alternative is getting an empty form and having to look up the original entity in another browser tab.
Comment #19
Leksat CreditAttribution: Leksat at Amazee Labs commented@samuel.mortenson,
Yes it would. Currently ContentTranslationController does this for regular node forms here: https://github.com/drupal/drupal/blob/8.3.0-alpha1/core/modules/content_...
(Attached image is a screenshot of a customized "Media file selector" (media_generic) widget we used on one of our old D7 projects. Not the most intuitive UI :D)
Comment #20
Leksat CreditAttribution: Leksat at Amazee Labs commented@slashrsm,
I agree that it would be nicer to use parent form language instead of the current content language.
So here is my attempt.
Additionally, I made that the edit form reflects the language select element value dynamically. If the language select element exists on the parent form.
Comment #21
samuel.mortensonWhat benefit is there to passing the langcode with a query parameter, instead of trusting the core functionality of prefixing routes with the langcode (i.e. /fr/*)? I've never seen modules explicitly pass the langcode like this.
Comment #22
Leksat CreditAttribution: Leksat at Amazee Labs commentedWell, we can use system language prefixes/domains. But we have to be careful since language detection can be setup individually for different language type.
Also, using query parameter, it was easy to change langcode dynamically basing on the current language select value (in #20).
Comment #23
Lennard Westerveld@Leksat,
Your patch wasn't working on drupal 8.3.x but i have made a fix see my patch.
Comment #24
FaibyshevIf add new translatable entity by entity browser, new entity will be add with default site language. I added fix for it.
Comment #26
Lennard Westerveld@Faibyshev: I think your way of getting the current language is not always the right?
Because of the types of language detections i think this is the right way: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Language%... and LanguageInterface::TYPE_CONTENT
Comment #27
Faibyshev@Lennard Westerveld, Thanks for the advice, you are right. I have made changes. Thank you.
Comment #28
ziomizar CreditAttribution: ziomizar as a volunteer and at Station, East Atlantic Engineering commentedI've tested on drupal 8.3.x the patch at #23 and it works for me.
4. Create new content and upload image via Entity browser field, specify alt and title attributes for image
5. Add translation for created content
6. Try to overwrite entity browser's image attributes to new language (create translation for referenced media entity)
As result, it create new translation for referenced media entity.
Comment #29
Leksat CreditAttribution: Leksat at Amazee Labs commentedReroll of #27 on 8.x-1.x branch.
BTW, #27 still applies nicely to 8.x-1.4.
Comment #30
pavlosdan CreditAttribution: pavlosdan commentedDoes this work with the View widget as well? or should I open a different issue? Currently on a translated node if you select a translated media entity, the original node changes to point to the selected translation as well. Expected behaviour was that the media on the original node would not change.
Comment #31
adr_p CreditAttribution: adr_p commentedI'm not sure if in fits the scope of this issue, but we needed something similar but from a media entity perspective: creating media entity translations when they're added to content in a different language (e.g. referencing "English" media entity in a "Spanish" content would create a Spanish translation of that media entity).
Please ignore the patch if it doesn't fit in here.
Comment #33
adr_p CreditAttribution: adr_p commentedHere's the updated patch that covers LanguageInterface::LANGCODE_NOT_SPECIFIED.
Comment #34
samuel.mortensonPutting back into needs review for #29.
Comment #35
samuel.mortensonIs there another (cleaner?) place we can do this? Overriding the prototype in this way seems like a workaround.
I also wonder if the logic this patch is adding makes sense for everyone. From reading it - if I am viewing a translation of a Node and edit one of the referenced entities using Entity Browser, I am automatically creating a translation of that entity. Will every user want this?
This patch also still needs tests, so setting back to needs work.
Comment #36
adinac CreditAttribution: adinac as a volunteer commentedReroll of #27 on 8.x-1.x branch.
Comment #37
badrange CreditAttribution: badrange at Digia commentedPutting back into needs review for #36
Comment #38
samuel.mortenson@badrange This issue still needs tests, and my feedback from #35 has not been addressed.
Comment #39
ayalon CreditAttribution: ayalon commentedWe are using this patch on every multilingual site. Whithout it, the handling of translated entities is completely broken.
Comment #40
ziomizar CreditAttribution: ziomizar as a volunteer and at Station, East Atlantic Engineering commentedThis seems to be a major issue
Comment #41
ziomizar CreditAttribution: ziomizar as a volunteer and at Station, East Atlantic Engineering commentedThis lead also on lost user data in a multilanguage website, and should be marked as bug not task as it is now.
Imagine this scenario, multilanguage website in italian and english:
- user create the english version of a page "Type A" as alt in the image write "This is the title and alt of the image"
- user translate the "Type A" in italian and set as alt for the image "Questo è il testo per alt e titolo dell'immagine"
You lost the english version, as the italian overrided it.
Comment #42
s_leu CreditAttribution: s_leu at Station commentedThe patch in #36 solves the problem for me too, but it sure still needs tests.
Comment #43
dksdev01 CreditAttribution: dksdev01 as a volunteer and commentedHi All,
Is there a patch for entity_browser 8.2.1 version? Patch #13 used to work with 2.0.0-alpha2.
thanks,
Comment #44
7thkey CreditAttribution: 7thkey as a volunteer commentedThis should be focus on 8.2.x, it is not really fixed!
Comment #45
stewest CreditAttribution: stewest as a volunteer and commentedI now get
Does this mean this patch is in 2.2.0?
Comment #46
Spokje@stewest
Sadly not, it means you got very lucky that such an old patch made for the 8.1 version survived for so long.
This really needs to get some TLC to get into the next release. I rerolled #36 against the latest 8.2.x-dev version to get this back on the radar.
Also upped the version from 8.x-1.x-dev to 8.x-2.x-dev.
Looking at #41 (and due to the lack of tests) I've left it at Needs work
Comment #47
SpokjeComment #48
SpokjeD8.6 test failures are caused by https://www.drupal.org/project/entity_browser/issues/3054210, which makes running tests for this module on D8.6 fail as mentioned by oknate here: https://www.drupal.org/project/entity_browser/issues/3054210#comment-131...
Note that the tests fail because of using a function that exists only from D8.7 upwards, so it doesn't mean the test is failing, just that the test couldn't run. The mentioned function is only used in the tests, not in the actual module, so using this patch on D8.6 is still OK.
Comment #49
Ghost of Drupal PastNote this is under testing at Smartsheet. We will report back.
Comment #50
RenrhafUpdating patch to avoid a PHP warning :
Comment #51
SpokjeReroll of patch in #50 against latest 8.2-2.x
Comment #52
SpokjeTags cleanup.
I will be trying to get at least the scenario from #41 in as a start point for (more) testing during the upcoming weeks.
Comment #53
ayalon CreditAttribution: ayalon commentedWe did a lot of testing and have this patch in place on a lot of production sites.
Test are not failing and not using this patch might lead to a loss af data.
We should go a step ahead.
Comment #54
ayalon CreditAttribution: ayalon commentedComment #55
xavier.massonReroll the patch with the 8.x-2.x
Comment #56
pcambraConfirming RTBC
Comment #57
Lukas von BlarerDoes anyone know of an issue regarding this for core's media_library?
Comment #58
Lukas von BlarerWorks perfectly! Thank you!
Comment #59
ozin#55 Patch does not work with layout builder in Drupal 9.3.0
Using LanguageManager service makes it works with Layout Builder.
Comment #60
sokru CreditAttribution: sokru as a volunteer commented+1 for adding this. Manually tested patches from #55 and #59, works nicely, but settings "Needs work" since maintainer has required tests for this issue.
Comment #61
Lukas von BlarerI found a issue against core media library: #3221720: Improve workflow for translating Media entities with the Media Library
Comment #62
Lukas von BlarerComment #63
ita08 CreditAttribution: ita08 commentedReroll of patch 2721665-55 for version 2.8.
Comment #64
bserem CreditAttribution: bserem as a volunteer and at Annertech commentedPatch #63 has some coding standard issues (spaces). It also seems that it does not address layout builder like patch #59 does.
#59 is the preferred patch here.
Comment #65
dewalt CreditAttribution: dewalt at EPAM Systems commentedUpdated #56 patch to use with latest module version.
Comment #66
dewalt CreditAttribution: dewalt at EPAM Systems commentedComment #67
bserem CreditAttribution: bserem as a volunteer and at Annertech commented@dewalt I assume you meant patch 59 was the source, as there is no patch in 56, and 56 is just a typo mistake.