I'm currently contemplating Entity Translation integration for Inline Entity Form.
The idea of IEF is that you manage referenced entities right there on the parent entity form.
Let's assume a use case of a node referencing commerce products.
So:
1) if you're editing an english node, newly added products also have "english" set as their language.
2) If you're using Entity Translation and adding a french translation for the node, then the product values should be saved under "fr" as well.
(Assuming ET is enabled for both entity types).
So, looking at the ET codebase briefly told me that I should instantiate a translation handler for the inline entity form (which will then handle the tricky parts for me, such as changing the source language). However, ET doesn't use #parents to store the translation handler in form state, which means there can be only one. Hence this request to allow multiple.
Alternatively, please suggest how I should proceed in regards to this matter.
Thanks!
Comment | File | Size | Author |
---|---|---|---|
#29 | et-form_handlers-1865244-29.interdiff.do_not_test.patch | 665 bytes | plach |
#29 | et-form_handlers-1865244-29.patch | 36.82 KB | plach |
#26 | et-form_handlers-1865244-16.patch | 36.79 KB | plach |
#26 | et-form_handlers-1865244-26.interdiff.do_not_test.patch | 1.75 KB | plach |
#17 | et-form_handlers-1865244-17.patch | 36.69 KB | plach |
Comments
Comment #1
plachWell, coupling the translation handler with
$form_state
was initially a quick and dirty addition to deal with AJAX calls that do not involve going through the usual entity edit routes, which among the rest are responsible to set the current form language (seeentity_translation_edit_page()
). I think a more consistent work on this using#parents
would be welcome, but I'd need to see a patch to be sure.Comment #2
candelas CreditAttribution: candelas commentedany news on this? we need a way for products variations to get translated...
thanks for your excellent work :)
Comment #3
plachI spent the last days working on the integration between ET and IEF (a tough task, btw). The attached patch should enable IEF to integrate with ET. The goal of the patch was to decouple the translation handler from the form state and just store there the need contextual information, that is the current form and source languages. This allows to instantiate a translation handler in any point of the execution flow through a centralized (singleton) factory, which is the sole responsible for ensuring we have just one translation handler instance for each entity. In turn this avoids losing the contextual information after restoring it from the form state (this is mainly needed when proessing AJAX requests, as pointed out in #1).
The patch supports nested entity forms by cleaning up some assumptions in the entity form massaging and (most importantly) by allowing to register child translation handlers: when the root translation handler contextual information is updated all the children are updated accordingly. This should allow us to support arbitrarily nested entity forms (actually I didn't tested that, just a single nesting level :).
The attached patch includes the #1947764: Improve bundle translatability checks API clean-up, which willl be committed soon. There is also an interdiff for reviewers' convenience.
Disclaimer: this has the potential to break lots of stuff (although it performs many clean-ups that simplify the current code), hence it needs to be carefully tested before commit.
Comment #4
plachThis comment should mention only the form language.
We should probably have also a method to remove the child.
An array_unshift would probably be more efficient here.
Comment #5
plachRelated issue: #1545896: Add Entity Translation integration.
Comment #6
plach$this->last should be returned only if $entity_type is empty.
Comment #7
plachRerolled after the latest commits and addressed the minor issues above.
Comment #8
klonos...coming from #1344672: Field Collection: Field translation (entity_translation) support.
Comment #9
bforchhammer CreditAttribution: bforchhammer commentedNote, patch #7 seems to fix an EntityMalformedException which occurs when adding taxonomy terms on the node page; see #2008366: EntityMalformedException when adding new tags to taxonomy.
Comment #10
bforchhammer CreditAttribution: bforchhammer commented#7: et-form_handlers-1865244-7.patch queued for re-testing.
Requesting tests again, because previous run didn't include menu tests (plus we've had a few bug fixes since the patch was added).
Comment #11
ciss CreditAttribution: ciss commented#7: et-form_handlers-1865244-7.patch queued for re-testing.
Comment #12
candelas CreditAttribution: candelas commentedany news? thanks :)
Comment #13
candelas CreditAttribution: candelas commentedi downloaded the dev version and applied the patch #7 because i was getting the EntityMalformedException when adding new tags to taxonomy in a blog on Commerce Kickstart distribution.
now when i try to translate a blog new i have the problem that i cant translate. sorry for my bad english. i try to explain my best:
i have english and spanish languages.
i make a english new.
i save it (button with save and translate disappeared)
i go to translate and i see that spanish it is not done.
i ask to translate but i get edit instead. there are not the 2 buttons on top right with both languages and i can choose the language from a select.
i choose the spanish language from the select and then save.
what it makes is that it changes the original language, instead of making a new translation.
if you have any doubt about my explanation, please, tell to me and i try to explain again.
thanks a lot for your work :)
Comment #14
csedax90 CreditAttribution: csedax90 commentedsame problem, the patch doesn't solved the issue
Comment #15
bojanz CreditAttribution: bojanz commentedThis is a refactoring, it's not meant to solve any Kickstart issues directly.
Comment #16
plachRerolled after the latest commits.
@candelas:
Did you run the updates and clear the cache after applying the patch?
Comment #17
plachTested the attached patch with #1344672: Field Collection: Field translation (entity_translation) support. and it seems to be working well. I will commit it soon.
Comment #18
candelas CreditAttribution: candelas commentedthanks very much @plach for so much hard work. i am finishing a work and i will be able to test next week :)
Comment #19
agoradesign CreditAttribution: agoradesign commentedI've found something very important:
The patch uses the following command 5 times:
Well, unfortunately this breaks PHP 5.2 compatiblity, as you cannot call func_get_args() directly as function parameter. You have to first store the result in a variable and use that as parameter. Similar (older) core issue incl. fix: https://drupal.org/node/1411592
Comment #20
plachThanks for reporting, would the following alternative work?
Comment #21
agoradesign CreditAttribution: agoradesign commentedNo, just tried it. But when I try to create a new node, I still get the same error:
Seems that there's no way around doing it like this:
Comment #22
plachWeird, they should be totally equivalent. Are you sure you replaced all occurrences?
Comment #23
agoradesign CreditAttribution: agoradesign commentedYes, I'm sure. In fact, before I tried your approach, I had already replaced all 5 occurrences with the two-line variant to fix it. Starting from that working code base I've changed it to your approach, and it stopped working, giving me the error message above.
From php.net:
http://www.php.net/manual/en/function.func-get-args.php
Comment #24
ciss CreditAttribution: ciss commentedUnfortunately agoradesign is right. The problem seems to be caused by the way PHP tries to determine the current scope. Fun fact: It will work if func_get_args() gets called as the first argument.
You can try this yourself on sandbox.onlinephpfunctions.com choosing the right PHP version.
Unfortunately their sharing feature is currently broken, so here's the code I used:
Comment #25
plach@ciss:
Thanks for the additional background :)
I think reversing the arguments is not good for DX so I guess will just have to bite the bullet and go with #21. I'll provide a new patch ASAP.
Comment #26
plachHere it is.
Comment #27
interdruper CreditAttribution: interdruper commentedAfter the patch #26, I get this error:
Strict warning: Only variables should be passed by reference en EntityTranslationHandlerFactory->getHandler() (line 79 of entity_translation\includes\translation.handler_factory.inc).
Comment #28
agoradesign CreditAttribution: agoradesign commentedSeems to be a similiar problem. Line 79 is:
The return value of entity_load() should be stored in a variable first to avoid the PHP warning
Comment #29
plachAnd now we should be ok.
Comment #30
bojanz CreditAttribution: bojanz commentedQuestion: Will something like this need to be done in D8 core, or does that API already support translating two entities on the same form?
Comment #31
plachIn D8 we have entity forms that natively support form language and a proper Entity Translation API, so the translation controller is way thinner and has only the reposibility of massaging the form. I don't think we will need anything like this.
However there's an issue to ensure entity forms can be nested: #1728816: Ensure multiple entity forms can be embedded into one form.
Comment #32
joel_osc CreditAttribution: joel_osc commentedThanks for the patch, this is great work. I did notice one thing now with patch, when I go to add a translation the fields which are not translable are showing even though I have entity_translation configured to hide them.
Comment #33
plachSorry, I cannot replicate #32: I will commit this in a couple of days, if you can reproduce the problem on a clean installation please post the steps before commit, otherwise we will open a follow-up. We need a wider testing audience here.
Comment #34
joel_osc CreditAttribution: joel_osc commentedSounds like a good plan - I have numerous patches on my system so it could be just something I induced locally.
Comment #35
das-peter CreditAttribution: das-peter commented@plach I totally agree with #33 since this seems to solve #1925848: Pathauto generates language neutral alias on node creation too.
Comment #36
klonosYeah, #1344672: Field Collection: Field translation (entity_translation) support. seems to need it to move forward too. So, lets just commit and see if there are still issues. In that case, we can file separate follow-up issues.
Comment #37
plachCommitted and pushed, thanks everyone for testing. If you find related issues, please link them here.
Comment #39
plusproduit CreditAttribution: plusproduit commentedHello,
I reopen this issue, because there seems to be a problem when you update a vocabulary with ET translated terms, here's how to replicate:
That's not an option with a 100+ terms vocabulary, any ideas ?
Thanks
Comment #40
klonosPlease open a new issue. Thanx.
Comment #43
pbuyle CreditAttribution: pbuyle commentedIn #2285355: Translations of the parent entity are lost when creating a child entity with an Inline entity form, I've got an issue. I've two translation handlers on the same form. They both add a language selector to the form, with the same key. So the second handler ends up overriding the first handler's language selector.
Comment #44
plach