I'd really love if this module supported entity translation. I know there's 2 scenarios this would be required under:
- A - paragraph field on the host entity is marked to be translated, but the individual fields on the paragraph entity are not
- B - the paragraph field on the host entity is not to be translated, but the fields on the paragraph entity are
I decided to start investigating scenario A. I made some progress but it's by no means complete.
The patch attached creates a clone (using replicate module) of the paragraph module when the 'add translation' form is loaded and on save this is associated with the translated version of the host entity. However, there's a couple of big issues with it.
- The paragraph entity is created on the 'add translation' form load, rather than when the translation is saved.
- If the values in the paragraph form fields are modified on the 'add translation' form, then the changes aren't saved to the database. However, if you re-edit it later, it works fine
I think the second issue is because the paragraph field on the host entity isn't attached to the form correctly or something. I think if we managed to solve that, we could also come up with a different solution to avoid the first issue too.
| Comment | File | Size | Author |
|---|---|---|---|
| #319 | paragraphs-entity_translation-2452675-319.patch | 61.72 KB | aquaphenix |
| #318 | paragraphs-entity_translation-2452675-317.patch | 61.74 KB | Igumnov_aleksey |
| #270 | paragraphs-entity_translation-2452675-270.patch | 68.7 KB | codium |
| #256 | simpletests.png | 431.18 KB | codium |
| #256 | tests.zip | 15.22 KB | codium |
Issue fork paragraphs-2452675
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 #1
ciss commentedComment #2
ryanoreilly commentedEDIT: Misread description. Disregard.
Comment #3
miro_dietikernote that we are pushing a well supported translation status in D8 at issue:
#2414913: Support entity translation of paragraphs
With diff support
#2433099: Provide a custom diff plugin
including a tmgmt integration...
#2462263: Support paragraphs translation.
Hope you're not going a completely different route here.
Comment #4
ciss commented@miro_dietiker: i'm currently porting a field_collection entity translation patch to paragraphs (or at least trying to). I'm currently online in #drupal and #drupal-support - might be a good chance to put our heads together.
Edit: 7.x in my case.
Comment #5
miro_dietiker@ciss i'll be at montpellier / Dev Days, personally only wed-sun. Until then we try to make all relevant pieces of D8 Paragraphs translation including its TMGMT integration ready. During easter weekend i doubt you will find me in IRC.
Comment #6
camdarley commentedI'm looking after a solution for scenario B.
As Jason Dean said in #2388185: Fully support Entity Translation:
This is exactly the kind of behavior I need for most of my clients: if we're editing a node with a paragraph field in language A, the paragraph field widget is showing the paragraph item entity in language A. If in language B the paragraph item entity is shown with language B.
Should we have a different issue for this scenario?
Comment #7
liquidcms commented@miro_dietiker, any progress on this? Any chance the D8 solution can be back ported to D7?
Comment #8
ziobudda commentedAny news about this topic ? It is important that this module can be work in Drupal 7. Thanks.
Comment #9
miro_dietiker@liquidcms I just updated about the related D8 entity translation status and we can support whoever works on a D7 port. But our team is D8 only and we will not work on a D7 port on our own.
Comment #10
damienmckenna@miro_dietiker: Are you looking for someone to comaintain the D7 version?
Comment #11
miro_dietiker@DamienMcKenna i'm not even one of the maintainers. We just helped pushing the D8 port. :-)
Comment #13
7thkey commentedHi there, any news about the entity translation support?
Comment #14
SoBiT commentedAre there any news on this topic?
Comment #15
mihai_brb commentedI agree with someone that commented on this topic and said that we should not rely on Replicate (Field collection module does not require Replicate).
We should avoid creating the paragraph entity whenever the translation form is prepared simply because one might not save the translated entity.
From my perspective there are 2 alternatives for working with entity translation.
1. Enable translation for paragraph field, no translation for paragraph fields.
With this approach, you end up having a distinct paragraph entity for every language.
When implementing this, all we need to do is make sure that the original paragraph entities are properly attached to the translated entity.
The current code does not save paragraphs to the translated entity because they are not properly attached to the form. There is a never-ending function that is embedding paragraphs and I suspect that's what is needed to be called in the attach process.
2. Do not translate the paragraph field, but allow translation for paragraph entities.
With this approach, you end up having the same paragraph entity for every language, but allow entity translation do its magic via field translation on paragraphs level.
It might be easier to sync data between languages but harder to make paragraphs work with the host entity language.
I could spend some time and fix this.
I just need to know what is the official Paragraphs team feedback on this.
Comment #16
liquidcms commented@mihai_brb i am going to be looking at this as well (today); but if you come up with solution before i do; please post. :)
as for the approach taken, i honestly don't see the use case for option #1, so i think #2 is the only valid approach here. think of it like this:
Yes, a Paragraph is both an Entity and a Field, but in this case the concept that it is an Entity should take precedence and NOT be allowed to be translated, just the way the paragraph's parent entity (node, user, etc) isn't available for translation. Then, as you stated, let ET (so stupidly named as it is NOT translating entities) should do its thing and simply translate the underlying paragraph fields (if they have been individually designated as being translatable).
That being said, the first (simple) part of this is to replace the standard ET field setting that shows at the bottom of the field settings form to enable/disable ET for this field and simply replace it with a note stating "paragraph fields can not be translated; set their underlying fields as translatable or not".
The second (harder part) is making sure that the underlying fields get assigned the language of the paragraphs parent. Note this last sentence is somewhat misleading as technically, for ET, the parent entity does not have a language (it is UND); but its edit form selects the language being used (i.e. the language that should be assigned to all the entity's fields (and its paragraphs' embedded fields) which have been set as translatable.
Comment #17
David Malavasi commentedHi,
I get some strange behaviour with this patch.
First, when i added the patch everything went as expected and as described.
I added a translation for the node. The translation was not saved yet, which is fine. The I edited the translation, translated all my entities and... Voila! Exactly what I want.
The next day i try to do the exact same thing.... I add translation for the node, I save it. But then when I edit the translated nodes the Paragraph fields are not showing! It says that no paragraphs have been added yet.
I tried to find out what the reason for this was, disabled and enabled some modules, tried other approaches like #30 from here, went back to this patch again and suddenly it worked again. And then the next day... the exact same thing... the paragraph fields are not showing.
How can this be??
I hope I can help making Paragraphs translatable, my time is just very limited.
Comment #18
liquidcms commentedThis is my first crack at patch for supporting ET; but sadly i was working against -rc3 rather than against -dev. Patch is pretty small though so perhaps someone can apply changes to -dev and re-post... and of course test.
i took the approach i mention in #16 by disabling ability to set translation for the paragraph field itself and instead i replaced the std field setting for this with a note: http://screencast.com/t/zgQkurQzqS
also, i was not able to track down where to remove the (all languages) text that gets added to fields which are shared: http://screencast.com/t/Vxg6KqVb2KS if someone can figure that out i would greatly appreciate it.
also, i have done minimal testing, and no testing with revisions. might still be some work in that area.
Comment #20
liquidcms commentedissues i have seen so far with my patch:
1. when editing translation, the (all languages) suffix is added regardless of how the field is set (technically i think this is bug in ET; but unlikely it will get fixed there)
2. when editing translation, the translatable paragraph fields are not pre-filled with the text from the base language - not sure how big a deal this is as it is a bit of a nuisance that it is pre-filled anyway; although to be consistent, it likely should be (likely not too difficult to fix but will leave it until other testing proves if my patch is worth continuing on)
3. for this to work, the ET setting for "enable language fallback" needs to be set (of the 3 issues; this seems to be only possible show stopper to me)
Comment #21
pmusaraj commented@liquidcms yes, issue 3 is an important one. And related to it, the paragraphs fields won't show if "Hide shared elements on translation forms" is checked, under the node type settings.
Comment #22
mihai_brb commented@liquidcms not sure how translation delete on parent entity will work for referenced paragraph entity translations.
Comment #23
liquidcms commented@mihai_brb, hmm.. interesting.. so when a translation is deleted for a parent.. i guess this (should) delete the field records which are of the language of that translation. so for paragraphs, this would NOT delete the paragraph since it is UND; but should delete the paragraph's fields which are (now, with this patch) in that language.
yes, this will need to also be added and yes, i haven't looked at that case yet.
Comment #24
honza pobořil commentedBtw, if we turn on field translation for field on Paragraph bundle, the data added to this field by node form will not be saved. So shoudln't this issue be marked as bug?
Comment #25
mihai_brb commentedJust tested patch #18 with Entity translation.
Paragraph field no longer has the option to be translated, that should be fine.
On my Paragraph entity bundle I have 2 fields, one translated, the other is not.
When I am on translate form for a node I do not get the original paragraph filled in.
I can create new paragraphs but this way I end up having a paragraph entity for every language.
From what I understand the goal would be to have the paragraph field referencing the same paragraph entity, and only translate the referenced paragraph entity fields (when needed). For example, a referenced paragraph entity could have translated and untranslated fields. A use case for this would be when someone has referenced paragraph with images and text. Images are the same for all languages, and you only want to translate the text.
Comment #26
liquidcms commentedthis patch is now against latest -dev and also addresses issues in #21 and #22
#21 - if ET is set to hide shared fields para fields were not showing up on translation form as the para field itself is not translatable. with this patch if any translatable field within the para in the source lang is filled in; then the entire para field form is visible when translating. ideally this would only show those fields within the para field which are not shared; but i havent added that yet.
NOTE: i had to change system weight of para module to 20 to be > weight of ET module as i didnt see a way for it to not override any changes i made before hand. if someone wants to review my code and come up with a cleaner way to do this so weight doesnt need to be changed.. :)
#22 - using hook_entity_translation_delete() i go through the parent entity and find any para fields with translatable fields and then go through and delete those field records.
from #25:
hmm, nope, i dont think that happens. if you have a para field with a translatable and untranslatable field and you fill both of these in for the source language. then you go to translate, yes, you do not get original value filled in but the you do get the para field there (and the untranslatable field is filled in with text from source language). if you now enter translated text for the translatable field and save the translation; pretty sure you dont get a new para record.. only get the para's translatable field record added in the new language.
as for not filling in original source text; yes, i have not gotten to that yet as it seems like a bug in ET anyway as it means the user needs to now go and delete the garbage text from those fields before entering correct text. i get why they do this; and likely not too hard to fix here.. but wasn't high on priority list.
Comment #27
liquidcms commentedand the patch
Comment #29
7thkey commentedAdded hook_install for the paragraphs_update_7102() so new installations get the correct weight.
Fixed some non existence properties errors when creating new content.
Fixed when adding paragraphs field into a translatable entity the message: “This is a Paragraph field. It is not translatable as a complete entity. Please set the translation mode for the paragraph's individual fields.” and removed the Field translation checkbox.
I still don’t get it the use of $form['#after_build'][] for that. @liquidcms, tell me why you did this? I commented this section of the code just in case.
Fixed to show (all languages) on child fields with no translation enabled. For some reason it doesn’t work with multiple images, hell it doesn’t work on parent either (maybe entity translation issue?)
What doesn’t work so far:
- Copy all data fields from origin language when creating a new translation.
- On translatable image fields with “Field synchronization” enabled, when adding or updating images should sync among translated languages.
Comment #30
7thkey commentedComment #32
liquidcms commented@7thkey, hey, thanks for jumping in on this:
1. hook_install for weight: yup, good catch
2. notices cleanup: great, i always miss some of those
3. after_build rather than form alter: when i looked at it it wasn't available in form alter; my guess is because we have now changed the weight of the module that we get to see this after ET has modified.
4. show (all languages): sweet, that one was killing me.
todo:
5. Copy all data fields from origin language when creating a new translation.
6. On translatable image fields with “Field synchronization” enabled, when adding or updating images should sync among translated languages.
yes, i agree, 5 would be nice to be consistent; although not sure i really get the point of ET doing this anyway.
6, i don't understand. isn't field sync for i18n?
Comment #33
RAFA3L commentedHello, trying to make it to work with a nested bundle I notice something wrong in #29 patch...
$form[$parent_field['field_name']][LANGUAGE_NONE][0][$fieldinfo['field_name']];
should use $delta
$form[$parent_field['field_name']][LANGUAGE_NONE][$delta][$fieldinfo['field_name']];
with the index 0 always use the first paragraph field and not the current one.
This fix the duplicated Shared Labels on each field too.
Another thing...
I don't know the utility of this function, I got many errors: "paragraphs_entity_translation_delete", I comment it and errors gone. the fields are deleted properly without this equally.
Notice: Trying to get property of non-object in paragraphs_entity_translation_delete() (line 910 of /XXX/sites/all/modules/contrib/paragraphs/paragraphs.module).
Notice: Undefined index: field_name in paragraphs_entity_translation_delete() (line 913 of /XXX/sites/all/modules/contrib/paragraphs/paragraphs.module).
Notice: Trying to get property of non-object in paragraphs_entity_translation_delete() (line 914 of /XXX/sites/all/modules/contrib/paragraphs/paragraphs.module).
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mgy_dev.field_data_' doesn't exist: DELETE FROM {field_data_} WHERE (entity_id IS NULL ) AND (language = :db_condition_placeholder_0) ; Array ( [:db_condition_placeholder_0] => en ) in paragraphs_entity_translation_delete() (line 916 of /XXX/sites/all/modules/contrib/paragraphs/paragraphs.module).
Comment #34
liquidcms commentedthose are just notices; not real errors.. just means some variable not initialized. pretty sure if that function is not there the translation records will not be deleted; just the paragraph itself is deleted so you wont see it.. but you have left clutter in your db. check the db.
Comment #35
sumachaa commentedpatch #29 is not working for paragraph bundles which has field_collection items. Fields within the field collection is always getting saved in the same language
Comment #36
liquidcms commentedre #35 - doesn't surprise me.. unlikely something i would look at but feel free to suggest a patch.
Comment #37
oo0shiny commentedI made some changes to the patch in #29 to get rid of some of the errors and notices when editing and deleting Paragraph pages. Not sure if this is the correct way to go about it, but it seems to be working for me.
Comment #38
al.ex commentedHere's a new attempt at making paragraphs compatible with Entity Translation. This implementation makes use of Entity Translation's handler class system to provide an actual ET handler for translating paragraph items.
Prerequisites
Working
Todos
Comment #39
sumachaa commented#38 seems to be the ideal way forward. Faced few issues, updating a latest patch
did the testing using Entity Translation 7.x-1.0-beta4 (please let us know if this needs to be the latest dev version)
Comment #40
csedax90 commentedHello, i've installed the dev version (and applied the patch #38), with entity_translation at the latest dev and i18n at stable version. I've create a 2 new paragraphs bundles but when I click on the Add button it return this:
Some has the same problem?
Comment #41
aruuska commentedI've applied patch #38 to Paragraphs 7.x-1.0-rc4 and when I click on Add button it return ajax error:
Fatal error: Class 'EntityTranslationParagraphsItemHandler' not found in .../modules/contrib/entity_translation/includes/translation.handler_factory.inc on line 93
ReadyState: undefined
Comment #42
apugacescu commented@aruuska, had the same issue, please check where the 'translation.handler.paragraphs_item.inc' file was created by applying the patch, it should be in [paragraph's root dir]/includes/translation.handler.paragraphs_item.inc , patch may fail and add it somewhere else like it happened to me. Also the rest of the classes are actually in entity_translation's include dir so class declaration file location is not so obvious.
Comment #43
joekersIt is my understanding that all patches apart from the original patch is using method B from the issue summary? Surely method A gives the most flexibility so that content editors can have different paragraphs items per translation, rather than having a set number of items from the source language.
@stella Did you make any further progress on this after your first patch? I'm trying to use this patch but I'm trying to prevent the entities from being saved on page load.
Comment #44
geertvd commentedOverall #38 is working pretty nice for me.
This assumes that all fields under the paragraph will also be translatable which is not necessarily the case.
This works for my use-case but the parent entity's language is not always the interface language, we might need find a better way to fix that.
Is this still an issue? I couldn't reproduce it.
Comment #45
sumachaa commented@geertvd, re: #44
Comment #46
oknatethis update to the patch fixes issue where we might not want to pull language from $GLOBALS['language']->language.
Comment #47
oknatethere's a typo in this patch. How do I remove it?
Comment #48
oknateAdding a new patch. The initial paragraphs_item created doesn't update the fields when the hostEntity is updated. So you end up with a node in english, but a paragraph item with fields in LANGUAGE_NONE.
Adding a patch for that.
Comment #50
damienmckennaThis needs tests.
Comment #51
n_e_ commentedWhat's the expected behaviour after applying #38?
This is what I'm seeing:
1. Add new node. Save.
2. Add paragraphs item to node. Save.
3. Add translation. Translation loads paragraphs item with fields populated with source language.
4. Edit fields on the paragraph with translated values and save.
5. The translation displays the values from the source language, not the ones entered in the step above.
6. Edit the translation, the paragraphs item is no longer visible on the translation. It does still exists on the source language node.
Comment #52
bleedev commentedRe-rolled #48 against 7.x-1.0-rc4.
Also removed the requirement for the parent entity to be untranslated, as we have a requirement to have the language specified.
Comment #53
sleepingmonkUpdated patch #52.
Added check for i18n_language_content so nested paragraphs work on node add.
Added is_object in paragraphs_entity_presave() on $et_handler->hostEntityHandler because handler sometimes returned empty with nested paragraphs.
Comment #54
Fidelix commentedComment #59
ksemihin commentedHi all
Its a temporary solution for correct work with module Entity translation.
For correct work with ET module you should be apply next patches:
After apply next diff for patch entity_translation-prepopulate-form-state-2339315-8.patch
Best regards,
Comment #60
sleepingmonkSmall update to patch #53 on the view method.
This is to ensure we see the content language.
However, the full conditions are:
In my tests, just removing the $langcode override based on entity_translation condition allows the field's language from $item to be used, which is what we expect.
I welcome feedback on this particular point.
NOTES:
- We have 3 levels of nested paragraphs_items.
- We're running the entity_translation patch from @ksemihin's comment above (#59)
Patch #9 for module Entity translation Link: https://www.drupal.org/node/2339315#comment-10884422
Comment #61
sleepingmonkSorry, got content_language backwards. Should be language_content.
Comment #62
jiv_e commentedMe and @wroxbox at Affecto had to fix this somehow on our client project. So here's our solution as a separate module. We hope it can help in the solution.
If you have already paragraphs_item entries in the entity_translation table it's good to remove them first.
db_query("DELETE FROM entity_translation WHERE entity_type = 'paragraphs_item'");http://dropbucket.org/node/7669
You should use these versions of entity_translation and paragraphs modules:
You should apply these patches before this works.
Our situation:
1. We have nodes translated with entity_translation.
2. Paragraphs field is not translatable (it's forbidden by the Paragraphs module).
3. Paragraph items are translatable by entity_translation module.
4. Paragraph item fields are translatable.
The module allows us to translate nodes with separate paragraphs items. In other words it's possible to have different number of paragraph items on every translation.
Comment #63
johanvdr commented@jiv_e
I have a question about your helper module paragraphs_translation (to make entity translation work better). Did you use it with the paragraphs-7.x-1.x-dev with any patches applied? Any other modules needed? I tried it and the extra paragraphs of the translated para fields are still visible in the source language.
Only paragraph fields in the para field are set as translatable. Not the para field itself.
Comment #64
jiv_e commentedHi!
I'm sorry! I asked @wroxbox to add details on the applied patches, but he's obviously too busy. :)
Here!
I edited the original comment also.
Comment #65
johanvdr commented@jiv_e
Not working for me at the moment. Deleted the translated ET para bundles first.
Applied the ET module patches. (applied patches on the ET 7.x-1.0-beta version of the module)
What patches were applied on the paragraphs module itself in your use case? (applied on which version of the module?)
Comment #66
jiv_e commentedSorry, I forgot to check paragraphs patches!
projects[paragraphs][version] = "1.0-rc4"
projects[paragraphs][patch][] = "https://bitbucket.org/!api/2.0/snippets/tierakehitys/B8epy/5d975866c6bd6..."
I don't really now about these patches. I just did the module. Maybe @wroxbox can tell more about these. I just picked these up from the makefile.
Comment #67
johanvdr commentedThank you for your help.
Can I bother you with one last thing? In your makefile what version of entity translation is specified? I could patch the dev version of ET.
In the end it does not work for me. The extra paragraphs appear in the source language still.
entity_translation-7.x-1.x-dev with patches
entity_translation-prepopulate-form-state-2339315-8.patch
et-i18n_taxonomy-1661348-24.patch
undefined_property_menu-2511966.patch
paragraphs-7.x-1.0-rc4 with patches:
paragraphs_entity_translation_support_2452675.patch
paragraphs_translation
Comment #68
giorgosktried #61 patch with instructions from #60
but when saving translated content I get this fatal error
when trying to set a particular paragraphs field to "enable or disable translation" I get this
I had paragraph field not translatable when I try to enable translation for it I get
Comment #69
jiv_e commented@johanvdr Sorry for the inconvenience! I edited the original comment and added the details there. See: https://www.drupal.org/node/2452675#comment-11082609
Comment #70
giorgoskFollowed instructions from #62
following patch has a warning
https://bitbucket.org/!api/2.0/snippets/tierakehitys/g9kXM/c8945329eee99...
Notes #62 3. is a little confusing
I think you mean the settings here admin/config/regional/entity_translation > TRANSLATABLE ENTITY TYPES
On installing the module does not show up in the modules list
paragraphs_translations.module should be named paragraphs_translation.module and then it can be enabled
After that It seems to work as advertised with some small problems
a) there is not language local tabs when you edit one language to go directly to the other language
instead you have to go to
b) the Language switcher (Content) BLOCK is not working (translation is disabled when you are on original language)
Language switcher (User interface text) BLOCK works fine though
But there is a major problem as well last note from #62 is not correct
"The module allows us to translate nodes with separate paragraphs items. In other words it's possible to have different number of paragraph items on every translation."
I Created new paragraph item) only on the translated language (secondary language) and it actually appears on the original language ?!!
On the original language edit forms an empty paragraph item appears that if its DELETED it deletes the ORIGINAL paragraph item (meaning from the translated language)
Comment #71
Tronux commentedI got translating Paragraphs working (not with the entity translation module but with the same goal):
I noticed the additional module: paragraphs i18n. (so you are using the latest paragraph version which you can update without keeping the patches in account)
Download the dependencies.
Then you'll notice it saves the paragraph in an entity (paragraph bundle) for that language.
Now I had issues rendering the paragraph field in my node.
So I made a .tpl specially for that content type that has that paragraph field. And copied over my node.tpl code from my basetheme to that file.
Then I added this code to render the paragraph field.
Hope I helped,
- thomas_vc
Comment #72
leo_li commented@GiorgosK
I got the same problem when deleting the translated paragraph, after applying @jiv_e 's patch in #62
Comment #73
leo_li commented@GiorgosK
For the problem when deleting the translated paragraph, I found the reason and somehow "fixed" it.
Take a look at the file "paragraphs/ParagraphsItemEntity.inc", and the problem it's in the "deleteRevision()" function.
In fact, I don't know exactly how to make the code inside works with entity translation, so I disabled all this part:
At least, it works for me. Hope it helps for you too.
Comment #74
parrot commentedProblem with paragraphs inside taxonomy term.

breaks at entity_save($term).
Comment #75
7thkey commentedStill needs work...
Comment #76
arnested commentedI rerolled the patch against current 7.x-1.x-dev and added an implementation of
hook_entity_translation_source_field_state_alter()(added to entity_translation 7.x-1.0-beta5).Comment #77
arnested commentedAdd a version of the patch from #76 but rerolled against current release 7.x-1.0-rc4.
PATCH HAS WRONG PATCH LEVEL.
Comment #78
arnested commentedAnd the version of the 7.x-1.0-rc4 reroll with the correct patch level.
PATCH HAS WRONG PATCH LEVEL.
Comment #79
arnested commentedThis time it should be with the right patch level. Sorry for the noise.
Comment #80
edi44 commentedPatch #79 is not working for me and return an error message if i try to add a paragraph item
PHP Fatal error: Class 'EntityTranslationParagraphsItemHandler' not found in .../sites/all/modules/contrib/entity_translation/includes/translation.handler_factory.inc on line 93...
Instalation:
entity_translation 7.x-1.0-beta5
paragraphs 7.x-1.0-rc4 + #79 patch
paragraph bundles are enabled in entity translation configuration
paragraph field in node is not translatable
fields inside paragaph items are translatable
any ideas?
after patch there is no folder /includes with file translation.handler.paragraphs_item.inc
Comment #81
arnested commentedOK, I seriously managed to goof up my patches yesterday. I went home and got a decent nights sleep and took extra care rerolling them today.
So attached now is a rerolled patch against current 7.x-1.x-dev with an an implementation of
hook_entity_translation_source_field_state_alter()(added to entity_translation 7.x-1.0-beta5).There is also a patch against current stable release 7.x-1.0-rc4.
The patches should have the right patch level and shouldn't leave out half the code this time. Really sorry for the noise.
Comment #82
arnested commentedComment #83
edi44 commentedThank you very much! 7.x-1.x-dev + patch#80 is working very well :)
Comment #84
damienmckennaChanging status to "needs review" so the testbot does its thing.
I still think there ought to be tests for this.
Comment #85
sitiveni commentedHi there,
A quick test (haven't looked to deep into it tho) seemed pretty ok when the paragraph item is attached to a node. However, when attaching it to a taxonomy term I get the same error as parrot (#74). Briefly looking at the code revealed that the newly added class EntityTranslationParagraphsItemHandler (file translation.handler.paragraphs_item.inc) uses 'node' hard coded.
What if you'd replace 'node' with $entity->hostEntityType()? Would that work?
Comment #86
sitiveni commentedTo tie in with my comment above, here's an idea how to use $entity->hostEntityType() instead of hard coded 'node':
Also note that the host entity needs to be available to proceed.
Comment #87
RAFA3L commentedThanks! #80 for 7.x-1.0-rc4 work fine here, after the content is created with several paragraphs all work fine, the versions in another languages area created too, but I have some shared fields, for example images and numbers. If later I change one this, the field go out of sync in the other languages, I can deal with that, but this is a normal behaviour?
Comment #88
RAFA3L commentedSorry, I was making the paragraph field translatable and not the fields inside. Now all the shared fields are synchronized, perfect!
Comment #89
RAFA3L commentedHello I had some problems with nested paragraphs and the patch #80 for 7.x-1.0-rc4, then I try with the dev version and work better. Only two things:
When I add a second or more paragraphs each one copy the same text on a translatable field in the first paragraph.
After upload an image inside a paragraph got this error: Warning: Invalid argument supplied for foreach() en element_children() (line 6568 of /htdocs/test/includes/common.inc).
EDIT: Both cases occur only when create a page the first time, if you save and then edit again the problems dissapear
Comment #90
james.williamsHere's a re-rolled patch that includes something based on the suggestion from comment 86 above.
Comment #91
titouilleHi,
ET enabled on paragraphs.
"Basic page" translatable at field level.
Paragraph bundle "p_a" embed in "Basic page" as non translatable, with translatable fields.
Paragraph bundle "p_b", embed in "p_a" as non translatable, with translatable fields.
With #90, when I click to add a p_b paragraph, I encount the following ajax error:
When I see the code on translation handler :
It iterate on entities to go to parent while the current entity has 'hostEntity' method. The problem is the process iterate while it find paragraphs, and in the last loop, it set $this->hostEntity as the parent (not a paragraph).
In my case:
p_b: check hostEntity method: yes; $this->hostEntity = p_a.
p_a: check hostEntity method: yes; $this->hostEntity = basic page
In the loop, we are on basic page and we try $this->hostEntity->hostEntityType()... But no way because node doesn't has hostEntityType() method...
With a little check it work correctly to add paragraph in paragraph:
But I think it's not the better way... But no time yet to find more stylish way to do it now...
No one has encounted this problem with the last patch ?
Comment #92
james.williamsSorry, I'd rerolled the patch and included suggested changes without testing those changes. Thanks for testing for us! Here's another attempt, based on what I think was really intended. Again, untested.
Comment #93
james.williamsArgh, just spotted a PHP warning that would be thrown. So ignore my last comment! Try again...
Comment #95
ralkeon commentedHi all, I had an issue by adding some paragraph of the same type to a single node, and I find someone that had the same problem here:
https://www.drupal.org/node/2786235
I found that the issue comes with this patch, and I try to fix it, I don't know if this is a good way to solve, but in my case it works! Hopes this helps someone else.
Comment #96
ralkeon commentedSorry forgot to include translation.handler.paragraphs_item.inc in the patch. Here it is.
Comment #97
ralkeon commentedHi all, I faced the last issue again while using nested paragraphs, I tried to fix it, hope it helps and it works!
Comment #98
idebr commentedComment #99
jbhovik commentedHi everyone. I've been following this thread with great interest. Will this be released as part of the Paragraphs module soon? I know it's hard to say sometimes, but I thought I'd ask.
Comment #100
bleedev commentedFound an error using nested paragraphs in #97
Updated patch attached.
Comment #102
proweb.ua commentedafter enable translations in filed settings
#100 patch
Fatal error: Class 'EntityTranslationParagraphsItemHandler' not found in /sites/all/modules/entity_translation
/includes/translation.handler_factory.inc on line 93
Comment #103
bleedev commentedFix bug causing incorrect language in translated paragraph fields.
Comment #104
sleepingmonk@proweb.ua
Try registry rebuild with
drush rr.You may need to install registry_rebuild first:
drush dl registry_rebuildComment #105
proweb.ua commented@bleedev, thanks
#103 works
Comment #106
amme commentedComment #108
RAFA3L commentedTrying #103 I found that if you add an additional paragraph after the node was created this doesn't appear in the translated version.
1- Create a node with some paragraphs
2- Translate the node
3- Edit the node and add a new paragraph
4- The new paragraph only appear in the edited version (view and edit mode)
Edit: Making the paragraph field not translatable (the text field in the paragraph bundle yes) and unchecking "Hide shared elements on translation forms" in the entity translation options show the new paragraph in the translated content, but empty.
Comment #109
bwoods commentedI used patch #97, and it seemed to work for me with new content. However, I had initial language neutral content that was being deleted when I changed to a locale (initially, the site was set up as all Language Neutral, but now most content types and entities are being moved to specific languages. As a workaround for the older content, I commented out these delete calls in the paragraphs_field_update function in paragraphs.module:
$item->setHostEntity($entity_type, $entity, $langcode, FALSE);
$item->deleteRevision(TRUE);
This seems to keep the Paragraphs intact. I haven't tested fully, but I'm guessing that with these commented out, I wouldn't be able to actually delete Paragraphs, so my goal is to revert back once I've switched all content from language neutral to the specific language.
Comment #110
PawelR commentedI've found a bug in #97, when I create parent entity in default language, and wanted to translate it it wasn't falling back to default language.
Paragraphs fields on the form were empty instead of getting copy of default language.
In order to fix the problem I've changed that code in paragraphs_field_widget_form_build():
to this:
Comment #112
pivica commentedTo @PawelR and others - creating a patch is a great thingy but its much more easier to track changes and do reviews in patches if you guys provide interdiff as explained in https://www.drupal.org/documentation/git/interdiff.
Comment #113
teknocat commentedI found that in the current supported version of the module, scenario A seems to work fine. Enable translation on the field of the host entity, but do not enable translation of the fields within the paragraph bundle. Enabling translation on both causes the paragraph field not to render any content.
I'm not sure what the ultimate plan to fix this is, but for now I just updated the README.txt file with a note. I was thinking of submitting that as a patch, but as this issue is being worked on that doesn't seem appropriate.
Comment #114
pol@PawelR: your last patch is incomplete.
@bleedev: Patch from #103 is working flawlessly with latest dev version of paragraphs. THANKS !!!
Comment #115
polHere's an updated patch.
Comment #116
polSorry last patch is not good, there are missing files.
Here the good one.
Comment #117
amme commentedComment #119
polUpdated patch, including patch from #2562463: Parent entity access check throws PHP notice because $nid nor $vid are set.
Comment #120
polHi all,
Since using this patch, I had a lot of problem in my Fieldable Panels Panes.
The previous patch assume Paragraphs to be used with Nodes (see comment #110), but Paragraphs can be used with any kind of entity, like Fieldable Panels Panes.
The following patch fix this, now it's working without any single glitches.
Comment #121
polHi all,
The patch I submitted in #120 has a slight problem.
When I create a Fieldable Panels Pane(FPP) containing paragraphs, the variable
$langcodepassed to paragraphs.field_widget.inc::paragraphs_field_widget_form_build() is set to 'und'.And thus, when saving the FPP, the paragraphs saved in the DB are saved with the 'und' language.
And all the paragraphs fields are empty => This is the real issue for the client.
To get over this, the creation of a FPP has to be done in 2 steps. First, create the FPP without the Paragraphs, then edit the FPP add the paragraphs.
If we do that, then it works fine.
I'm trying to find a solution for this issue since I posted the patch, but to be honest, I reach the end of my knowledge and patience, a little help would be greatly appreciated.
Comment #122
bleedev commentedRe-rolled #103 with update from https://www.drupal.org/node/2831973
Comment #124
pol@bleedev
Your patch is not valid. This assume that a paragraph is always attached to a node. However, you can attach paragraphs to Fieldable Panels Panes or Beans.
You should use:
Instead of
Comment #125
pbuyle commentedHere is a re-roll of @Pol's patch in #120 with the update for #2831973: Make langcode property public by @bleedev that I'm currently testing.
Comment #126
pbuyle commentedMy latest patch in #125 does not include support for non-node host entities as mentioned by @Pol in #124.Comment #127
pbuyle commentedAnd here is the updated patch:Based on patch from @Pol in #120Adding changes for #2831973: Make langcode property public from @bleedev in #122Adding change for non-node host entity suggested by @Pol in #124In initial testing, I was able to create a content with three levels on nested paragraphs and translate them.Comment #128
pbuyle commentedI got mixed up please disregard comments #126 and #127.
Comment #129
pbuyle commentedComment #130
pbuyle commentedWhen using the patch in #127 with three levels of nested paragraphs (paragraphs in paragraphs in paragraphs in nodes), I encountered issue with MalformedEntityException. The issue was with the line
$language = entity_language($instance['entity_type'], $form['#entity']);proposed by @Pol. On some occasion, theform['#entity']does not match the actual host entity type. I applied the patch for #2564327: Host entity problems (ajax errors / nested paragraphs / UI speed) and changed the line to$language = entity_language($element['#host_entity_type'], $element['#host_entity']);.The attached patch combine fixes for this issue, #2564327: Host entity problems (ajax errors / nested paragraphs / UI speed) and #2831973: Make langcode property public and allowed me to properly edit and translate paragraphs.
Comment #131
pbuyle commentedPatch in #130 is broken, here is the correct one.
Comment #132
polDear @pbuyle,
Your patch is working flawlessly.
We should maybe ease the work of the maintainer and provides single patches... but to be honest, I have the impression that the D7 version is no more maintained :(
Comment #133
maico de jong#131 Is mostly working for me:
1. When setting 'Hide shared elements on translation forms' @admin/config/regional/entity_translation to TRUE on the parent entity, paragraphs are not shown in the edit form since the paragraph itself isn't translatable. (the fields inside are)
2. When setting 'Hide shared elements on translation forms' @admin/config/regional/entity_translation to FALSE on the parent entity, paragraphs are shown but "(all languages)" is missing from the paragraph field. This should be added because paragraphs are deleted for all translations when you remove it on any translation edit form.
Comment #134
feuerwagenRerolled #131 based on current 7.x-1.x-dev branch.
Comment #135
polHi Feuerwagen,
Your patch doesn't apply.
Comment #136
polHere's an updated patch.
Comment #137
badrange commentedHeads up; this thing just got committed to Entity Translation - it may affect this patch:
https://www.drupal.org/node/2849464
Comment #138
fadeslayer commentedversion = "7.x-1.0-rc5+11-dev"
core = "7.x"
project = "paragraphs"
datestamp = "1487357266"
I have a problem with entity translation and Paragraphs, after applying the patches
#136 2452675-7.x-1.x-reroll.patch
and #134 paragraphs-entity_translation-2452675-134.patch
above.
When I set display mode of paragraphs field to default (full) I have only untranslated fields printed, every field set as "translatable" will not be rendered whatsoever.
I found that modifying paragraphs_field_formatter_view paragraphs.field_formatter.inc, adding
and modifying entity view call as
(e.g. passing site langcode to the function)
renders every field, be it translatable or not.
I don't know if it is the right way to do so, and I ask for developers to inspect this problem.
Comment #139
pol#136 needs to be rewritten using new Entity Translation API.(see change record)
I will try to do it this week.
Comment #140
pcoffey commentedHey there! A couple of days ago I managed to re-roll this and get Entity Translations working for Paragraph items on a project I'm working on. Here's the re-rolled patch!
Comment #141
bwoods commentedI've just started testing and making edits, but so far, #140 is working for me. Thanks!
Comment #142
guillaumeduveauIt seems that patch #140 applies to 7.x-1.0-rc5 and not 7.x-1.x-dev. Moreover, when patching upon 7.x-1.0-rc5, I get this error :
Comment #143
pfenriquez commentedI created a patch based on #140 that works on 1.x-dev.
The patch must be anyway tested in order to verify if it works for op issue.
Comment #144
polAre you sure that your patch is complete ?
Tips: use git diff --cached to create your patch.
Comment #145
pfenriquez commentedSorry, I pushed only the patch for the rejected part. I try to add the complete patch as soon as I can.
Comment #146
garphyHere is a reroll of #140
Comment #147
garphyBetter with the patch file...
Comment #151
RAFA3L commentedWorking in a site today I notice that the entity_translation table have +6k records and I have only ~300 paragraphs items in 3 languages. Now I have +6k records because I delete and import the content several times with feeds and this process never delete the previous paragraphs items. You can delete paragraphs items or nodes and the records still there forever in the entity_translation table.
Comment #152
howdytom commented#147 is working great with paragraphs (7.x-1.0-rc5) on "a clean installation". Excellent job! Thank you all.
However I’ve noticed that existing paragraph Items disappear when using combination of i18n and entity_translation. schwarli4783 opened a issue here: Paragraph Items disappear when using combination of i18n and entity_translation
Comment #153
ciss commentedThis prevents translated field values from being displayed if the paragraphs_item entity is marked as not translatable (use case B from the issue summary). The same code can be found in the translation handler added by this patch.Edit: This works correctly after marking paragraphs items as translatable in the entity translation configuration. It stands to reason wether this should be required for paragraphs items that only act as intermediate/wrapping entity, but since field_collection currently lists the same configuration requirement in its readme there might be no way around it. /Edit
For reference, this is what field_collection does: FieldCollectionItemEntity::view()
Field Collection also checks the translation status of the parent entity (haven't checked, but I assume this will happen recursively), which seems to be a more sound approach: EntityTranslationFieldCollectionItemHandler
Comment #154
ciss commentedDeprecated since entity translation 7.x-1.0-beta6.
I'd also like to emphasize what DamienMcKenna has stated twice already: We need tests, otherwise we'll continue to get manual confirmations for either case A or B without definitive proof that this patch is working for either.
Comment #155
ciss commentedThis line should read:
because entity_translation_get_handler() will return the last created translation handler for that entity type if the passed entity is null.
This is especially problematic when multiple paragraphs items are created and populated via entity_metadata_wrapper(), causing some translatable field items to be saved under the wrong language.
Comment #156
jbhovik commentedHi everyone,
I was wondering if I could interject something.
The entity key for language was defined as "langcode" in paragraphs-entity_translation-2452675-122.patch. Is there a reason why the entity key was specified as "langcode"?
Most other entities use "language" as their entity key for language (nodes, taxonomy terms, comments).
Also, Lingotek's customers rely on patches in this thread for translation of paragraphs.
I propose we change the entity key from "langcode" to "language" for paragraphs items. Attached is a patch with the change.
Comment #157
Jack0140 commentedHi everyone.
#147 is working great with paragraphs (7.x-1.0-rc5). thanks a lot.
However there is still some bug.
I have tested it and want to clarify more details about what #156 had mention.
From language neutral to specific language it works great.
However when a user selected a specific language for the node and created paragraph, the content of will disappear when user switching to other language including switching back to language neutral. This will only happen in editing page, for preview page the content still there. When switching it back to the previous language that we set at first, the content will appear back.
Is there any solution for this? As what if a user accidentally save to the wrong language and wanted to switch it back.
Comment #158
RAFA3L commentedYes this is one of two problems that I have too.
1- Fields are not translated in the paragraph creation
2- Paragraphs are not deleted when the node or paragraph is deleted
I fix this two problems with a custom module
Comment #159
stefdewa commentedRerolled #156 against 7.x-1.0-rc5.
Comment #160
ciss commented@jbhovik What patch did you base #156 on? Can you please add an interdiff?
@Stefdewa Please don't reroll against older commits. rc5 is not the most recent commit in 7.x-1.x.
Comment #161
jbhovik commented@ciss, I based my patch on paragraphs-entity_translation-2452675-146.patch. I changed only one line from "'language' => 'langcode'," to "'language' => 'language',"
Comment #162
codium commented@Stefdewa thanks for the newest patch. One problem I have is that on translation form paragraphs field is empty. I would like to see paragraphs items in original language ready to translate. Instead I see message: No Paragraphs added yet. Select a Paragraph type and press the button below to add one. So I need to recreate paragraphs structure on every translated node.
Comment #163
RAFA3L commented@codium this is because at the moment of the paragraph creation the fields inside are not properly translated, see #158
Comment #164
a65162 commentedI applied #156 patch, but there printed an error message
I try to find why it displays the error, then I figured out the "translation.handler.paragraphs_item.inc" that put in the wrong path.
It needs to put into the includes folder. It doesn't just put in the root of paragraph folder.
Comment #165
ciss commented@jbhovik What implications does this change have? Will it break existing sites that already have #147 applied?
This breaks
hook_entity_translation_insert()for nodes:translationsproperty of its host entity (if the translations are already set on the entity). This property contains an object which therefore gets passed around by reference.Comment #166
jbhovik commented@ciss,
I suppose it would depend on site specifics whether or not changing from patch #147 to #156 would break anything. I proposed the change because the Lingotek module contains some code that uses the entity key for language for every entity type, and "language" is common for most other entity types.
If certain modules or certain code requires "langcode" as the entity key for language, a change from #147 to #156 could break some things, but "language" should be a better choice for the language entity key.
Comment #167
ciss commentedIf they rely on a convention then they're doing it wrong. The patch already specified its language key in hook_entity_info(), and Lingotek should use that info. Imo this change serves no real purpose, and until someone has added tests for this issue we should probably stay away from introducing unnecessary changes to existing patches.
Comment #168
james.williams@ciss That's really well put, I'd totally agree. I was a bit worried seeing this back & forth about the extra unnecessary change.
Comment #169
mlanth commentedUpdate to #156 which adds a property_exists check for 'hostEntityHandler' in the paragraphs_entity_presave hook.
Was running into an issue where entity translation on a site for another entity was affecting updating existing paragraph items. This patch provided the fix, however it caused an issue after saving because it expects the handler to exist even though entity translation is not enabled for paragraph items.
Comment #170
codium commentedMy proposal of entity translation integration. Works pretty reliable. Most view & edit form issues fixed. Nested paragraphs support - which was pretty pain in the ass. I've followed https://drupal.stackexchange.com/questions/227510/how-to-translate-parag... guide as starting point. Based on paragraphs with patch: https://www.drupal.org/files/issues/paragraphs-entity_translation-245267.... Latest patches probably not supported, but I didn't need those.
Please let me know if it's working for you, than I'll add automatic tests for it and add other features like supporting other entities than node as parent entity.
Cheers!
Comment #172
codium commentedComment #173
codium commentedAdded patch #146 into #170
Comment #175
codium commented.
Comment #176
codium commentedComment #177
codium commentedComment #178
codium commentedComment #179
codium commentedCan anyone test it? More info: https://www.drupal.org/project/paragraphs/issues/2452675#comment-12654419
Comment #180
codium commentedComment #181
tinli commentedHi,
Tried your latest patch, on new translation save, it produces errors
Notice: Trying to get property of non-object in ParagraphsItemEntity->save() (line 446 of ParagraphsItemEntity.inc)
It seems that for newly created paragraphs translation, it's being checked for previous languages when there isn't one, I added a check isset to the original: isset($hostEntity->original) before assigning the original langauge.
That seems to fix it.
That is:
Change line 446 ParagraphsItemEntity.inc
There is prob a better or cleaner way, this is more of a concept on the error and a quick patch.
Scenario,
Created node 1 with English paragraphs
Click on translate, and add new translation for node 1.
On first save for this new translation, errors, though translations are saved. On subsequent edits, no errors.
After doing the check, no errors. This is for patch #179
Comment #182
codium commented@tinli thanks for your work and feedback. I was able to get rid off all warnings. However I have problem with built-in paragraphs tests. I've enable test feature and use it for manual testing and everything work. Fields IDs seems also same as in the code. I'm uploading the patch to check if here also tests will fail.
Comment #183
codium commented@tinli since tests passed here can you test it more? Especially case with nested paragraphs.
Comment #184
polHello,
I just did a quick code review on the style.
This line is too long and can be split in multiple lines. (multiple places)
use
!==instead of<>(multiple places)Empty line not needed. (multiple places)
I would separate with an empty line code paragraphs with a comment.
I would group those two unset in one:
Do you think it would be possible to add the documentation header of each method and the proper return type?
This line is too long and can be split.
I would use
!==as much as possible.I would not enclose the main code into the condition.
I think it would be much better to do an early return and move out the code from the condition.
I would move the main code out of the if and use an early return.
I would move out the code from the if and use an early return as well.
Beside that, nice work! Let's get this thing done!
Comment #185
codium commentedThanks a lot @pol for support. I think I've fixed most of it. I'm not sure about whole documentation changes in
EntityTranslationParagraphsItemHandlerclass, because I'm not author of most of the code there (derived from https://www.drupal.org/files/issues/paragraphs-entity_translation-245267...). Maybe contributor will want to update documentation also. Cheers guys!Comment #186
codium commentedBeside that I was trying to implement tests for it. I have an error upon running paragraphs_entity_translation tests. Basically tests are not able to even start due an error:
So I guess something is wrong with my exported feature with i18n functionality. However when I deploy this feature on 7 fresh installation I'm able to perform test scenario manually without any issues.
Could someone check it also? I'm uploading package my current state of paragraphs with this test module.
Comment #188
codium commentedComment #189
codium commentedComment #190
codium commentedComment #191
polHi,
Thanks for the fixes, I did another review.
Split into multi-line.
This should be on multi-line as well.
Does this mean that parent constructor could be called twice then?
use
===Split into multi-line.
Even if this is technically perfectly valid, I would do this on 3 lines instead of two for readability.
Same here.
This is perfect.
Split into multi-line.
Split into multi-line.
These are the same conditions and can be simplified.
First, check if the module exists.
Then inside that first condition, add the other conditions.
use
!==Use the inverse condition and use early return here as well.
I would invert the condition. First check if the module exists (or not), then check the type.
Comment #192
codium commentedThanks @pol, patch updated.
Comment #193
polHello,
Thanks for your responsiveness. I made another quick review, there is still some stuff to fix before submitting it to the maintainer.
I might be picky on the code-style but as we are going to rewrite some parts, let's do it right and use the Drupal coding standard ;-)
Thanks!
We could simplify the foreach and use the inverted condition here.
I think it would be better to use the $GLOBALS variable.
Always have an empty line before the return statement.
I think there is still room for improvements here.
If the module entity_translation doesn't exist, then the call to the parent is made twice.
Use ===
Split this into 2 lines.
Let's be consistent and use 3 lines instead of 2. Just like you did after.
The line is longer than 80 chars. Please split the line.
The line is longer than 80 chars. Please split the line.
Comment #194
codium commented@pol thanks for the patient, another update
Comment #195
polHello,
Here's a quick code review.
Could you please make sure to check the Drupal coding standard and fix the logic issue with the parent constructor called twice on some cases ?
thanks!
Please, remove any empty line after the start of the function.
Extra empty line.
Still the same issue. If the module entity_translation doesn't exists, then, the parent class constructor is called twice on the same parameters.
Line longer than 80 chars. Please, make sure that your changes are following the drupal coding standard... see: https://www.drupal.org/docs/develop/standards/coding-standards#linelength
Use single quotes.
I would not create the $merged variable.
I would write this:
Use
!==Comment #196
codium commented@pot could you send a guide how you configured phpcs in PHPStorm? Seems I'm missing some warning.
I don't understand why contructor can be called twice.
The code is basically:
I don't see the issue (call parent more than once) in the code.
Comment #197
codium commentedFinal patch from my side, I've no time to fix more code formatting things.
Comment #198
codium commentedComment #199
polHello,
Sorry for the point 3 in #195, I was not seeing it properly in dreditor.
I applied the patch locally and all good.
I modified a bit the code style and didn't change the logic.
Thanks!
Comment #200
codium commented@pot thanks a lot for support.
Comment #201
zestagio commentedHello,
I found a bug with translation delete for cases when paragraph field is multiple. For example host entity contains 3 paragraph entities (deltas are 0, 1 and 2).
Expected result: translations are deleted for each paragraph entity on translation delete of host entity
Actual result: translations are deleted only for paragraph with delta = 0.
It happens because:
All paragraphs have the same host entity. It's ok. But let's see method
EntityTranslationDefaultHandler::saveTranslations(https://cgit.drupalcode.org/entity_translation/tree/includes/translation...).$translationsis an object and as we know objects are passed by references by default and after call$translations->hook = array();(https://cgit.drupalcode.org/entity_translation/tree/includes/translation...) any other paragraph entities with delta != 0 can't pass this condition https://cgit.drupalcode.org/entity_translation/tree/includes/translation...I fixed a bug and code styling.
Patch attached.
Comment #202
polHello,
Thanks for the feedback.
Could you reroll your patch and please do not change the code styling. We've passed hours to review and provide an update.
Thanks!
Comment #203
zestagio commentedPatch without changes of code style.
PS: I don't understand, why you changed code style in some functions, which not related with issue, for example:
Comment #204
codium commented@zestagio thanks for the fix. I know that a code style changes in not related functions may be annoying in patch scope, but it was for cleaning some code also in the meantime. Now much more important is adding a tests for i18n feature.
Can you write test steps for your case?
Also I suggest this kind of refactoring (not tested), if you don't mind:
Btw can you explain purpose of cloning more to me?
Comment #205
zestagio commented@codium,
see #2452675-201: Entity translation support for Drupal 7. I described a problem there.
Comment #206
codium commented@zestagio, got it. Thanks
Comment #207
RAFA3L commentedAll work fine for me except two things
1) After save the node with paragraphs I get this error twice when view or edit the node. The same appears after applying the patch and trying to add a paragraph, but it was fixed after drush rr #104. Rebuild only fix the error when try to add a paragraph, the error in view and edit node still there.
2)paragraph_item in the table entity_translation is not deleted when delete the node. I report and fix this before in #158, but maybe is not the proper way
Thanks
Comment #208
RAFA3L commentedSorry, the error was not duplicated, they are two different errors
Notice: Undefined property: stdClass::$original in EntityTranslationParagraphsItemHandler->__construct() (line 60 of /Applications/MAMP/htdocs/pruebas/sites/all/modules/contrib/paragraphs/includes/translation.handler.paragraphs_item.inc).Notice: Trying to get property of non-object in EntityTranslationParagraphsItemHandler->__construct() (line 60 of /Applications/MAMP/htdocs/pruebas/sites/all/modules/contrib/paragraphs/includes/translation.handler.paragraphs_item.inc).Comment #209
RAFA3L commentedSorry again,
Swapping the lines 60 and 61 solve the problem 1
// before
$this->hostEntity->original->language !== $activeLanguage &&
isset($this->hostEntity->original) &&
// after
isset($this->hostEntity->original) &&
$this->hostEntity->original->language !== $activeLanguage &&
For the problem 2 I don't see any function to delete the paragraph items in the tablesentity_translation and entity_translation_revision when delete a nodes or paragraphs.
Could be something like this:
Comment #210
RAFA3L commentedProblem 3, in the edit form and trying to add a nested paragraph appear empty, no fields, even with and without translatable fields.
The patch in #136 work with nested paragraphs. I use this patch in several projects, for example www.miamismith.com and www.focalyx.com
Comment #211
codium commented@RAFA3L do you have paragraph reference field translatable or not?
Comment #212
RAFA3L commentedNot, the paragraph field in node is not translatable and fields inside paragraph are translatable
Comment #213
codium commented@RAFA3L then please send me feature with your content type or/and verification steps (problem 3).
Comment #214
RAFA3L commentedparagraphs 7.x-1.0-rc5+12-dev + Path #203
entity_translation 7.x-1.0
Create two paragraphs bundles, for example "section" and "box"
In paragraph "section" add a new paragraph reference field: "box"
Add a text field in each paragraph and make both translatable. Add another one with no translation (the problem happens with any field)
Paragraphs bundles are enabled in entity translation configuration
Create a Content type with Multilingual support: "enabled, with field translation"
Add a paragraph reference field "section" into Content type, no translatable
Create a node, add a paragraph "section" and then add "box", the box is empty. If I revert the patch the text field appear inside box
Comment #215
codium commented@RAFA3L
Please check test feature from https://www.drupal.org/project/paragraphs/issues/2452675#comment-12669718.
I'm testing exactly same case (at least this, I've understood from you description), all is working.
Maybe adding no translatable field to any of those paragraphs make the difference?
Do you testing it on clean Drupal installation?
Comment #216
RAFA3L commentedOk, I saw the problem, I didn't have the module i18n, now it works fine just by downloading it (without installing it). Would be useful make it required for the activation of the translate options. Thanks!
PS: Remember the problem 2, delete the paragraph items in the tables entity_translation and entity_translation_revision when delete nodes or paragraphs.
Comment #217
RAFA3L commentedSorry, that was not the problem, I downloaded paragraphs.zip in #186 and I didn't notice that this have an old patch (#185), Before activate the feature I saw that the module i18n is required, so I downloaded it and all worked fine (even without installing it). But now, installing again the paragraphs module and applying the patch #203, the nested paragraphs is empty again. i18n doesn't solve the problem.
Now I realize that patches #185 and #203 are very different.
With the patch #203 I tried with and without translatable fields, in any case don't display any field in a nested paragraph in the node edit form.
The path #136 It's the one that work for me (fixing by hand the problem with the deletion of items in the entity translation tables)
Yes I'm using a clean Drupal installation.
Problem 1 and 2: for me are fixed using #209
Problem 3: Empty nested paragraph in node edit form, don't fixed for now
Tomorrow I'll check the last patch and try to detect the problem
Comment #218
zestagio commentedI confirm this notice. I fixed it in attached file below.
Also I found one new critical bug for me. I have several paragraph bundles. Some bundles are translatable and some not translatable. Fields are disappear after saving untranslatable entity with untranslatable paragraph. It happens because we have condition:
($field['translatable'] === FALSE), but real value$field['translatable'] = 0Comment #219
RAFA3L commentedHello @zestagio, could you try a nested paragraph to confirm the problem 3, nested paragraphs don't display any field (translatable or not) in the node edit form
Comment #220
zestagio commented@codium, @Pol
Can someone explain what is reason to use
if (!module_exists('entity_translation')) {inside__constructmethod?You already extend class
EntityTranslationDefaultHandlerprovided by entity_transltation module and if the module not exists then extendable class not exist too. So, it looks like recursion.@RAFA3L, sorry I don't have free time for it :(
Comment #221
dan.ashdown commentedJust to add that I'm also experiencing the same "Problem 3" as @RAFA3L that he describes in #217 i.e. subparagraphs do appear in the node edit form but their fields have no values (they're not synced from the default language).
Fields are set to translatable.
Comment #222
RAFA3L commented@Dan.Ashdown you can see the fields but empty? In my case I can't see any field with the latest patches.
The empty fields did happen to me with the patch #185. I fix it with a custom module #158
Comment #223
dan.ashdown commented@RAFA3L so a bit more detail, top-level paragraphs do appear but with empty values. The second level you can add but is rendered as empty. So the same as your screenshot.
Comment #224
codium commented@Dan.Ashdown @RAFA3L - thanks for testing, confirmed your issue with newest patches.
Last patch that is working properly is #198. Here is updated version.
@zestiago
Thanks for your effort. In newest patch I've included only changes from: #218 - major bug, rest I'm consider as minor.
Based on this I think that strict type checking on boolean related thing should be consider as an anti-pattern.
I suggest to do not add any changes without creating simpletests first to avoid drawbacks.
Comment #225
dan.ashdown commentedThanks @codium, that's an improvement. I'm now getting the following issues though:
@RAFA3L can you confirm this?
Comment #226
codium commented@Dan.Ashdown
Thanks for testing, however I cannot reproduce any of your issues. For me create/translating nested paragraphs works without issues.
Can you provide me a feature with your content type configuration?
Comment #227
RAFA3L commentedThanks @codium! work fine!
But only two things more...
I notice a small problem when I add a top level paragraph with the option to add a nested paragraph and save it without add any nested:
The entity_translation module try to process all the fields in the top level paragraph, even the unset nested paragraph.
The other thing is the problem 2 in #209, when a node or paragraph is deleted the tables entity_translation and entity_translation_revision never delete the entities.
Comment #228
codium commented@RAFA3L
Do you mean saving node in this state?

Layout paragraph can reference nested paragraphs. I've saved in this state - no errors.
But I think the bigger problem is that required validation is skipped somehow in this case.
Comment #229
dan.ashdown commented@codium thanks, feature attached with a very basic content type and 3 levels of paragraphs. This doesn't show the "You are not allowed to add any of the bundles." error so let's ignore that as something to do with the other test content type. However translating still results in empty no paragraphs on the new translation.
I also get the same issue reported by @RAFA3L in #227
Comment #230
codium commented@Dan.Ashdown
It seems that you have lvl1 paragraphs in allowed bundles in your lvl1 paragraphs field in test content type.
I think this is a reason for your issues.
When I changed it I'm able to add nested paragraphs. Same situation is for lvl2 paragraphs.
IMO it cannot work properly out of the box.
Comment #231
RAFA3L commentedHello @codium, add the first level paragraph and don't add the second level nested, then save
Comment #232
dan.ashdown commented@codium
You can add lvl1 paragraphs to the node, lvl2 paragraphs to lvl1 and lvl3 paragraphs to lvl2.
Why wouldn't you specify a paragraph bundle? If you say the node cannot add lvl1 paragraphs that defeats the point.
You could think of this as a galleries node, to which you can add gallery paragraphs (lvl1), you can then add image paragraphs (lvl2) to the galleries paragraph and then you could add "meta tag" paragraphs to each image paragraph.
Comment #233
dan.ashdown commentedConfirming @RAFA3L's issue with my feature:
This occurs when saving a new node with a lvl1 value but no lvl2
Comment #234
codium commented@RAFA3L @Dan.Ashdown
Please check how I configured nested paragraphs in my content type. Fix for entity translation integration is built around this structure.
Seems like we don't understand each other.
Comment #235
dan.ashdown commentedThanks @codium, your feature doesn't have nested paragraphs which is the problem @RAFA3L and I are having.
So, using your feature, the fields on your node work as expected, great! However if you add a paragraphs field to your "Text" paragraph type you run into problems. This is the whole "nested" paragraphs problem.
Comment #236
RAFA3L commented@codium
Using your content_page feature do this
- Go to create a Content Page
- Select in Content > Paragraph type: "Layout" and Add a new one
- Save
- Error in #227
Comment #237
dan.ashdown commentedAh thanks, @RAFA3L, I missed the layout bundle. So this is indeed working as expected, hooray! I've also tried adding layout as an allowed bundle of layout so you can keep getting deeper. I've tried this to 4 nested levels which all work correctly when translating.
I can confirm the error @RAFA3L mentions in #236:
Comment #238
dan.ashdown commentedJust FYI, I've gotten my feature above to work with the latest patch (#224), the key was to make the paragraph fields NOT translatable but keep the "normal" fields as translatable.
Comment #239
codium commented@RAFA3L Cannot reproduce your bug - no errors/warnings/notices.
Maybe more detailed steps?
Comment #240
codium commentedThis is one & only proper way of creating content structure in such case. Setting paragraphs field as translatable have no sense, because the field value is an ID (simple reference in the end) and it cause creating totally new entity for every translation and then people wonder why Drupal is so big memory hog.
Comment #241
RAFA3L commented@codium
Set the paragraph like this and save the new node
Comment #242
codium commented@RAFA3L doing exactly the same.
Comment #243
codium commented@RAFA3L ok got it, I had language neutral. When I select real language, I'm seeing the error. However I have no time to fix it in nearest future.
I think there is more important bug with omitting required criteria of the field by paragraphs validate function. I'm doubt that this is related to my changes and probably deserves standalone ticket.
[UPDATE]
Verified it, seems not related to entity translation integration at all. Can someone check it also and create ticket for validation case?
Comment #244
RAFA3L commentedThanks @codium, great work! but remember that the entity_translation table is never cleared after a node or paragraph deletion, check your tables after delete one and the paragraph item still there.
Comment #245
codium commentedDoes anyone can test clearing entity translation table upon paragraph deletion?
Comment #246
RAFA3L commentedDoesn't clear here
Comment #247
RAFA3L commentedHello @codium
The new function paragraphs_entity_delete don't clear the database and cause a new error with nested paragraphs:
removeTranslations I think only reset the langcode of all the fields (paragraph or not) in the entity , not clear the database.
This is the new error when I delete a content with nested paragraph:
Why not just use this code?
Comment #248
codium commented@RAFA3L have you tested your code? If yes I'll use it instead or please update patch yourself
Comment #249
dan.ashdown commented@codium, what are you applying your latest patch (#245) to? I can't get it to apply cleanly to rc5. The patch references "paragraphs_modules_uninstalled" but that function doesn't exist.
Thanks!
Comment #250
RAFA3L commented@Dan.Ashdown do you get this error when delete a node with nested paragraphs?
.
Comment #251
codium commented@Dan.Ashdown 7.x-1.x-dev
Comment #252
dan.ashdown commentedThanks @codium, I can confirm it applies cleanly to dev.
@RAFA3L yes I get that error when deleting a node with nested paragraphs and a translation on the node. I do not get these errors with your suggested code. I left the early return code from @codium's patch though as I think that's useful.
Whilst translation is now working with the latest patch, content rendering appears to have broken, see screenshot. The content variable is now empty (in any language). This is using your content_page feature @codium.
Comment #253
dan.ashdown commentedActually, I've gotten the rendering to work correctly. I had to set the paragraph items language to "current language" at "/admin/config/regional/entity_translation" otherwise the field formatter was passing no langcode to the entity. FYI the "content_page" feature does not contain the entity translate settings.
Comment #254
RAFA3L commented@codium I can't found why the hostEntity is not getting during the deletion process, when is a nested paragraph. This cause the error #250 in line 51 when try to get the langcode of the host, so I validate $activeLanguage in the variable setting. Maybe the handler is not necessary when nodes/paragraphs are deleted.
// before
$activeLanguage = $this->hostEntity->language;
// after
$activeLanguage = (isset($this->hostEntity->language)) ? $this->hostEntity->language : LANGUAGE_NONE;
I change the paragraphs_entity_delete function too
Comment #255
codium commented@RAFA3L thanks for your effrot, @Dan.Ashdown for me rendering works with default ET settings also.
Comment #256
codium commentedAs I mentioned before I was trying to implement tests for ET integration. During tests execution I got an Exception:
But If I use same feature on clean D7 installation I'm able to create content page out of the box.
I've attached also my version of tests directory from paragraphs. Can anyone assists to resolve this issue? I think having tests for ET integration is a must.
Comment #257
RAFA3L commentedHello @codium I ran the paragraph test without errors, I saw and put your test file paragraphs_entity_translation.test in the paragraphs/test folder, but I can't see it in the test list admin/config/development/testing
First time I use Test, and I saw that the paragraph test require the module Panelizer, I use Display Suite instead. After install Panelizer, no errors.
Another question:
Implement the language setting of the paragraph fields in a handler class don't affect the site performance? Is there a way to call it only when a paragraph instance is created? because this is only required at this time to recreate the fields by language, not in view, edit, or deletion process. I realized this because of the error #250, this class runs everywhere where you see the paragraph.
I'm using this in live sites for a long time without problems, run only when the paragraph instance is inserted and I think do the same #158
Comment #258
codium commented@RAFA3L please add et integration test class to paragraphs.info file, then it should be visible.
About performance IMO it shouldn't affect site performance is meaningful way. However I didn't test it.
Comment #259
codium commentedComment #260
ciss commented@codium I want to see this committed as much as anyone, but it's not yet RTBC. The tests need to be provided as a patch and verified.
Comment #261
ciss commentedSetting to "needs work" as per previous comment. Also: Even though paragraphs itself uses a features module for its tests, I'd recommend to not rely on features for tests. Perhaps tests from eck and field_collection can be used as basis for paragraphs.
Comment #262
codium commented@ciss I've saw field collection tests. Tedious task, from my side no time for doing it in nearest future and I still don't see that error won't be similar. I suggests to try to it with Features first, if anyone want to be a volunteer for this task. I'm talking not only for writing those tests, but solving an error presented above, then I can write simpletests - no problem for me to write them.
Comment #263
codium commentedI've figured out how to bypass an exception during tests execution I've mentioned earlier. Tests are ready.
Comment #264
codium commentedWTF is happening with tests environment?
Comment #265
codium commentedJust wondering if putting all tests to single class will solve issue with Jenkins.
Can someone run those tests locally? For me locally all tests passed.
Comment #266
codium commentedNeed support
Comment #267
codium commentedComment #268
codium commentedComment #269
codium commentedReduce warnings output and remove entity translation configuration exception workaround.
Comment #270
codium commentedFix all warnings during tests
I think problem with an error during tests on Jenkins is related to patch apply. Here is more info to https://www.drupal.org/project/paragraphs/issues/2452675#comment-10815932. Does anyone have a clue how to solve this? How to create patch in way that there will be a sure that all files will be putted to paragraphs module directory?
Basically I think that test runner cannot locate tests class, because this is not under /docroot/sites/all/modules/paragraphs/tests but in /docroot/tests directory. Same case for all new files added by patch.
Link to build log: https://dispatcher.drupalci.org/job/drupal_d7/94023/console. Not very informative unfortunately, but still show that only legacy paragraphs tests were executed.
Comment #271
codium commentedComment #272
manojbisht_drupal commentedHi @codium,
Updated the module was getting error for Class "EntityTranslationParagraphsItemHandler", so applied the patch, but error was there. After I added that file in ".info" of module. It is working fine now. Please check.
Comment #273
stefanos.petrakisI would like to give a hand here, mostly by reviewing.
But, upon following the issue's history I got lost:
specifically between #169 and #170 there seems to be quite different coding happening.
I haven't seen anyone object so far, allow me to be the first one.
What happened between #169 and #170?
How is the discussion and patching till #169 taken into account from #170 and on?
@Codium et all working on this since #170: sorry for pulling the break, I appreciate all the effort you've put into this, but the work (from #170 and on) seems to throw away all the previous work in this issue, without any explanation and no linking to the previous patching that was in progress.
Comment #274
codium commented@stefano.petrakis What is your problem?
There are tests in my solution, just run them locally against previous patch and you will see, maybe everything was ok with previous patch, I don't know. Please do something useful instead of some kind of blaming.
@manojbisht_drupal
The class is in the paragraphs.info file:
files[] = includes/translation.handler.paragraphs_item.inc
Could you be more specific?
@self
Awating weeks for any kind of feedback, when it appeared - blames. WTF?
Comment #275
stefanos.petrakis@codium: No blaming was intended, my sincere apologies if you felt blamed.
Still, if I or anyone else wants to give a hand and starts reading the issue from top to bottom, it's difficult to follow the code changes from #169 to #170 (no interdiffs or further remarks). Most importantly, nobody can understand why those changes took place.
Once again, here are the important questions for making this issue manageable:
Comment #276
adsbisi commented@codium and all contributors , nice work this helped me a lot. What my current situation is that I have:
- Paragraphs: as field they have translation disabled. Fields inside paragraphs have translation enabled. I have field collections inside paragraphs (field collections have translation disabled, fields inside field collections have translation enabled).
Are those configurations by you guys OK, or I am making a mistake leaving field collections as field, inside paragraphs, with translation disabled (my opinion is that those configurations are OK, but please correct me if I am wrong)?
I have two languages, English and Spanish .When I want to edit some changes to paragraphs with field collections inside them for Spanish language, I would write something in those fields, I would save. Saving node passes, we go to a page, we see those values on Spanish language.
Situation is like this, in English field collection fields ,inside paragraph, we have value 1, in Spanish field collections fields ,inside paragraph, we have value 2. After I save node (text above) with value 3 for Spanish, situation would become like this:
English field collection field ,inside paragraph, now has value 2 and Spanish field collection field, inside paragraph, now has value 3, and beside that I can't see field collections values inside paragraphs in CMS, like it is restarted to default value, but on page I can still see that value 3 (untill I change it again and whole process repeats).
Did anyone have similar situation?
Comment #277
codium commented@stefanos.petrakis No problem, but be advised that I didn't throw away all work away until #170. My work is extension of #146 patch (what I mentioned in #170). To be honest I have no time to write about changes between 146 & 170.
Comment #278
codium commented@adsbisi my solution is not tested with Field Collection at all. IMO you have to choose: whether you are using Field Collection OR Paragraphs, combining both is not good idea.
Comment #279
adsbisi commented@codium yeah, I agree that ii is not good to combine them. In my case, when I edit field collection field for English, everything is fine after save. But saving something in Spanish, makes problems. So paragraphs with fields only work flawless for me, but with FC those are issues. I am investigating what is causing my issue, if I find the reason and solve it, I will comment that here, in case anyone ever get this issue like I did.
Thank you for quick answer, I appreciate all this.
Comment #280
denix commentedHi @codium, thanks for all your work and patience! what is the status of your patch now? any idea when it will be merged on a new release?
Comment #281
josecarlosss commentedHello, firstly thanks for all, now... i try apply patch #270 and return Error. Log of error:
patching file ParagraphsItemEntity.inc
patching file README.txt
patching file translation.handler.paragraphs_item.inc
patching file paragraphs.field_formatter.inc
patching file paragraphs.field_widget.inc
Hunk #3 succeeded at 417 (offset 1 line).
Hunk #4 succeeded at 440 with fuzz 2 (offset 1 line).
Hunk #5 succeeded at 471 (offset -4 lines).
Hunk #6 succeeded at 733 (offset -4 lines).
Hunk #7 succeeded at 1141 (offset -4 lines).
patching file paragraphs.info
Hunk #1 FAILED at 13.
1 out of 1 hunk FAILED -- saving rejects to file paragraphs.info.rej
patching file paragraphs.module
Hunk #1 succeeded at 105 (offset -1 lines).
Hunk #2 succeeded at 123 (offset -1 lines).
Hunk #3 succeeded at 422 (offset -2 lines).
Hunk #4 succeeded at 798 (offset -34 lines).
Hunk #5 succeeded at 836 (offset -34 lines).
Hunk #6 succeeded at 1323 (offset -51 lines).
Hunk #7 succeeded at 1357 (offset -51 lines).
Hunk #8 FAILED at 1460.
1 out of 8 hunks FAILED -- saving rejects to file paragraphs.module.rej
patching file content_page.features.field_base.inc
patching file content_page.features.field_instance.inc
patching file content_page.features.inc
patching file content_page.features.language.inc
patching file content_page.features.user_permission.inc
patching file content_page.info
patching file content_page.module
patching file content_page.strongarm.inc
patching file paragraphs_entity_translation.test
Any solution?
Comment #282
codium commentedHi @denix, due some error during tests (more info at https://www.drupal.org/project/paragraphs/issues/2452675#comment-12756995) and without any support to fix it i'm doubt that this go to release ever.
Hi @JoseCarlosss
This patch is for 7.x-1.x-dev version, are you aware of that?
Cheers
Comment #283
erichhaemmerle commentedHas anyone put together an easy to follow path for being able to translate Paragraphs using Entry Translation? Trying to follow these comments is extremely hard. They are all over the place with some patches for 7.x-1.0-rc5 and some for the dev version. Are these patches all inclusive or do I need to apply every single patch on this page in succession? I can't tell. I can't for the life of me make sense of any of it. Every time I try to apply a patch I either get an error or it says "skipped patch". I have Paragraphs version 7.x-1.0-rc5 and Entity Translation version 7.x-1.0 installed. Does anyone know what the proper procedure is as of now for getting this up and running if I want to be able to translate individual fields in my paragraph bundles?
Thanks!
E
Comment #284
bohus ulrychHello erich93063,
this is what I have set up on my site recently (extract from drush pm-list --type=Module --no-core --status=enabled):
Paragraphs (paragraphs) 7.x-1.0-rc5+12-dev
Entity Translation (entity_translation) 7.x-1.0+5-dev
paragraphs
* using patch 254: paragraphs-entity_translation-2452675-254.patch
* then you must enable "paragraphs Item" in "Translatable entity types" admin/config/regional/entity_translation
* then you will be able to enable translation for your paragraph fields
(Note: In my special case of nested paragraphs I had to manually update line 457 otherwise nested items had wrong language versions, you can see it easily in the db table for that field). I know that this is not right approach but it is working for me.)
//$this->{$field_name}[$host_language] = $value;
//unset($this->{$field_name}[$field_language]);
unset($this->{$field_name}[$host_language]);
)
So far this combination seems to be working for me.
Looking forward if anyone knows better way how to put all this together.
Comment #285
rcodinaAll patches have to be applied to dev version. If it that fails for some reason, the way to go is to clone the repository using git:
I can confirm that patch on #270 works like a charm. Thanks @codium!
Comment #286
denix commentedThanks @codium for your patch! it seems that people are happy with it. Can we have some of the devs have a look into this?
Denis
Comment #287
ciss commented@denix How did you draw that conclusion? As far as I'm aware there are still several comments in this thread that haven't been adressed yet.
Please note that this issue has 117 followers, at least half of whom have commented at some point. Unfortunately it's not sufficient to scan through the last dozen comments in order to understand the state of this issue.
Comment #288
james.williamsThanks for the amazing work here. Last time I dug deep into this was 3 years ago, before had moved it along so far. I had quite a lot of catching up to do! :-D
In the most recent patch(es), during
ParagraphsItemEntity::save(), it's quite possible for fetching the host entity/language to fail. Specifically, this is because$handler->hostEntitycan beNULL, but that should really be the current entity's host anyway, so$this->hostEntity()should suffice?As the subsequent code then relies on the host language having been picked up, to ensure fields are set under that language code, that needs to be rectified. See my interdiff - I've refactored a repeated pattern into a method, and used it in each place that relies on the host language. If the language cannot be found, field values are not moved around. Otherwise they get set against a 'NULL' language code, which is definitely wrong!
Comment #289
james.williams(I should add that the most likely case for when this can happen, is when combining field collection & paragraphs. Whilst it's not ideal to use those two together, it can be made possible, and anyway, I believe my suggested change makes the code more robust now.)
Comment #291
james.williamsVariable module was needed as a test dependency.
Comment #293
james.williamsIn fact, all of the contrib dependencies that the content_page feature adds, will be needed as test_dependencies. Sadly, as documented, those won't get picked up by the test runner until they've been committed. I don't know any way around that!
#2432629: PDO Exception when updating paragraph field due to panelizer is another example of an issue that needed a new test dependency - tests didn't pass in testbot until all had been committed.
The tests are certainly all passing for me, once those dependencies have been put in place.
Comment #295
james.williamsComment #296
james.williamsSpotted a couple more issues: a notice is thrown when the host entity does not have a 'language' property, plus the method I introduced in 288 really ought to allow specifying the entity type alongside the entity that can be optionally passed in. (It's only used for the original unchanged version of the host entity, so the entity type could be assumed. But hopefully fewer assumptions means more robust code!)
Comment #297
james.williamsCrikey, that was a botched upload somehow, very sorry! https://www.drupal.org/files/issues/2019-10-02/paragraphs-entity_transla... is the correct patch.
Comment #298
james.williamsFound another issue - the active language is not set correctly when the host entity is not a node or another entity type with the 'language' property. (For example, a bean.) Now that I've introduced that helper method on paragraph entities, it can be used here to get it right without hardcoding the language property.
I have to say, I've also noticed that the host entities' translations property can get polluted with changes made by the paragraphs handler, because
EntityTranslationParagraphsItemHandler::getTranslations()will return the object, which is passed by reference. So when I spotted the above issue, it was because the wrong language was actually being set in the host translations object! At least if we set the right code, it won't be wrong in the host translations object. But I suspect we might need to avoid passing the host translations object by reference (e.g. by addingclone?) fromgetTranslations(). I won't actually do this until I see any problems, but I can totally imagine there may be some.(I hope these patches upload correctly first time!)
Comment #299
james.williamsUrgh, I found an issue immediately, so please ignore the files in my last comment, use these instead. Sorry for all the noise.
Comment #300
nono95230 commentedI'm submitting a patch.
I took the paragraphs-entity_translation-2452675-254.patch patch, to integrate it into the new dev version of the paragraphs module.
This solves the problem well on my project.
Comment #301
james.williams@Nono95230 why did you go from patch 254, leaving out the work that's been done on numerous patches since then?
Comment #302
guillaumeduveau@james.williams because he's been working on it for 1 year
Comment #303
anybody@james.williams: Sorry to ask, but what's the final status here? I see you did a lot of work! #299 still has failing tests, which one should we use now to proceed and to have the best results currently possible?
Still any active development?
Thanks a lot for your hard work in this. Whao.
Comment #304
james.williamsThe real status of this ticket should be 'needs review', but the tests are failing (and so the status gets automatically reverted to 'needs work') because of a known documented issue. i.e. Test dependencies need to actually be committed before they get included by the test runner. At least, that was the case last time I looked at this - a good more time has passed since then! :-)
I've set the status back to needs review in the hope that might no longer be an issue. Perhaps a way forward on that, might be to get the extra test dependencies (entity_translation, i18n & variable) committed, even just temporarily, unless the module maintainers are happy to use local testing to see tests passing.
There's a possible issue I mentioned in comment 298, but I haven't seen any actual bugs caused by it (which I'm actually surprised by). I'd hope at least someone recognises what I was on about and could review that with some wisdom.
Meanwhile, Nono95230 added a patch (comment 301), which missed out on quite a bit of work from various patches. It's not clear if that included anything worth adding to the more recent one, but it was probably just a re-roll of an old patch, so can be ignored.
FYI, I do have patch 299 in use on a number of production sites.
Comment #305
james.williamsAh, the patch from #299 needs re-rolling.
Comment #306
anybodyThank you very very much. I really appreciate your work, @james.williams!
Comment #307
james.williamsHere's a re-roll. Some of the bits in the current patch have already been implemented (e.g. in #2564327: Host entity problems (ajax errors / nested paragraphs / UI speed), or to address coding standards issues in #2854100: Fix Coding Standards). Other hunks of the patch were nothing more than coding style changes too, which I've left out of this update, as coding standards are correctly addressed elsewhere. This patch is large enough, let's not include unrelated changes in it any more! As this is a re-roll otherwise, I haven't included an interdiff.
I did notice that there were 3 'TODO' comments left in the patch:
paragraphs_field_widget_embed_validate(), and the following reply said the issue it was for could not be replicated. I don't know if that meant the hunk the comment was for was not needed, or needed to stop a bug from being replicated. The code it related to (paragraphs_deleteconfirm_js()) has since been refactored away entirely. I've no idea if its replacement (_paragraphs_ajax_update_callback()) would need the hunk or not.EntityTranslationParagraphsItemHandler::__construct(), could quite easily be left for a follow-up issue. It's questioning whether, after switching an entity's language to language neutral, other existing translations should be removed or not.ParagraphsItemEntity::save(), is also about handling a language change on an entity. Specifically, whether to use entity translation API or not. If the current code works (and I can only presume it has been successfully tested/reviewed in that time), I suggest that could be left as a follow-up too.Comment #309
james.williamsSo the tests failed for the same reason as before, plus there are 42 coding standards messages on top of the current dev branch that this change adds. So the next steps are to:
1) Fix the 42 coding standards messages
2) Investigate at least the TODO comment in
paragraphs_field_widget_embed_validate(), if not the other two.Comment #310
james.williamsThis should resolve most of the new coding standards messages, hopefully.
Comment #311
gravisrs commented#310 usually works but in such case:
For all existing nodes all the paragraphs will vanish from database (both paragraphs_item tables entries, all field tables entries that was in that paragraphs but apparently the paragraph field itself - stays there with language field properly changed).
So at this point if anyone plans to have multilanguage paragraphs - make sure you turn on translations for it before any content is added.
Comment #312
anybodyWe're using this patch since months now successfully and I with james.williams in #307 that it would be worth to commit this at least to dev and document the missing pieces as follow-ups in separate issues. #311 is another example for that from my perspective. A 90% solution is better than none here and we get a better starting position with working tests then.
#310 seems to need a reroll against latest dev!
Comment #313
rcodina@Anybody I just cloned the repository and patch on #310 applied cleanly. So no reroll needed. Of course, the patch works well. Good job!
Comment #314
proweb.ua commentedparagraphs 7.x-1.0-rc5+37-dev + #310
Comment #315
gravisrs commentedLooking at #310 patch entry at diff --git a/paragraphs.info b/paragraphs.info
There should be context after last addition, even blank line. Otherwise CR/CR+LF/LF auto-detect in git-apply may fail on searching for the context.
Fixed patch attached
Comment #317
Igumnov_aleksey commentedWhen creating a new node in which there is a field with a reference to a paragraph and an entity ID has not yet been assigned, the multilingual node is thrown into such a warning:
I propose to add next changes to the patch:
Comment #318
Igumnov_aleksey commentedI have updated my patch. I changed the condition to most properly.
Comment #319
aquaphenixRe-rolling changes in #315 and #318
Comment #321
bluegeek9 commentedUnfortunately, Drupal 7 is End of Life and no longer supported. We strongly encourage you to upgrade to a supported version of Drupal.