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.

  1. The paragraph entity is created on the 'add translation' form load, rather than when the translation is saved.
  2. 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.

CommentFileSizeAuthor
#319 paragraphs-entity_translation-2452675-319.patch61.72 KBaquaphenix
#318 paragraphs-entity_translation-2452675-317.patch61.74 KBIgumnov_aleksey
#317 paragraphs-entity_translation-2452675-316.patch61.71 KBIgumnov_aleksey
#315 paragraphs-entity_translation-2452675-315.patch61.68 KBgravisrs
#310 paragraphs-entity_translation-2452675-310.patch61.68 KBjames.williams
#310 interdiff-2452675-307-310.txt12.14 KBjames.williams
#307 paragraphs-entity_translation-2452675-307.patch62.4 KBjames.williams
#300 paragraphs-entity_translation-2452675-300.patch28.74 KBnono95230
#299 paragraphs-entity_translation-2452675-299.patch69.49 KBjames.williams
#299 interdiff-2452675-296-299.txt1.69 KBjames.williams
#298 paragraphs-entity_translation-2452675-298.patch69.48 KBjames.williams
#298 interdiff-2452675-296-298.txt1.34 KBjames.williams
#296 interdiff-293-296.txt2.13 KBjames.williams
#296 paragraphs-entity_translation-2452675-296.patch69.47 KBjames.williams
#296 interdiff-293-296.txt2.13 KBjames.williams
#296 paragraphs-entity_translation-2452675-296.patch69.44 KBjames.williams
#293 paragraphs-entity_translation-2452675-293.patch69.37 KBjames.williams
#293 interdiff-288-293.txt510 bytesjames.williams
#291 paragraphs-entity_translation-2452675-291.patch69.25 KBjames.williams
#291 interdiff-288-291.txt384 bytesjames.williams
#288 interdiff-270-288-ignoring-whitespace.txt3.15 KBjames.williams
#288 paragraphs-entity_translation-2452675-288.patch69.12 KBjames.williams
#270 paragraphs-entity_translation-2452675-270.patch68.7 KBcodium
#269 paragraphs-entity_translation-2452675-269.patch69.45 KBcodium
#266 paragraphs-entity_translation-2452675-266.patch69.41 KBcodium
#265 paragraphs-entity_translation-2452675-265.patch68.89 KBcodium
#263 paragraphs-entity_translation-2452675-263.patch69.39 KBcodium
#256 simpletests.png431.18 KBcodium
#256 tests.zip15.22 KBcodium
#254 interdiff-2452675-245-254.txt1.86 KBRAFA3L
#254 paragraphs-entity_translation-2452675-254.patch27.8 KBRAFA3L
#252 example.jpg333.89 KBdan.ashdown
#245 paragraphs-entity_translation-2452675-245.patch27.72 KBcodium
#241 Screen Shot 2018-07-26 at 11.47.46 AM.png38.45 KBRAFA3L
#234 content_page.zip4.31 KBcodium
#229 paragraphs_translate_test.zip5.75 KBdan.ashdown
#228 empty_nested.png76.7 KBcodium
#224 paragraphs-entity_translation-2452675-224.patch27.43 KBcodium
#222 Screen Shot 2018-07-24 at 6.17.30 PM.png28.44 KBRAFA3L
#218 interdiff_203-218.txt1.48 KBzestagio
#218 paragraphs-entity_translation-2452675-218.patch27.44 KBzestagio
#203 interdiff_199-203.txt794 byteszestagio
#203 paragraphs-entity_translation-2452675-203.patch27.4 KBzestagio
#201 interdiff_199-201.txt23.49 KBzestagio
#201 paragraphs-entity_translation-2452675-201.patch22.24 KBzestagio
#199 interdiff.txt2.6 KBpol
#199 paragraphs-entity_translation-2452675-198.patch27.33 KBpol
#197 paragraphs-entity_translation-2452675-197.patch27.45 KBcodium
#194 paragraphs-entity_translation-2452675-194.patch26.54 KBcodium
#192 paragraphs-entity_translation-2452675-192.patch25.09 KBcodium
#188 paragraphs-entity_translation-2452675-187.patch24.49 KBcodium
#186 paragraphs.zip14.48 MBcodium
#185 paragraphs-entity_translation-2452675-185.patch24.08 KBcodium
#182 paragraphs-entity_translation-2452675-182.patch21.92 KBcodium
#179 paragraphs-entity_translation-2452675-179.patch20.57 KBcodium
#178 paragraphs-entity_translation-2452675-178.patch20.14 KBcodium
#177 paragraphs-entity_translation-2452675-177.patch17.81 KBcodium
#175 paragraphs-entity_translation-2452675-175.patch4.57 KBcodium
#173 paragraphs-entity_translation-2452675-173.patch15.5 KBcodium
#170 paragraphs-entity_translation-2452675-170.patch7.83 KBcodium
#169 paragraphs-entity_translation-2452675-169.patch14.28 KBmlanth
#159 paragraphs-entity_translation-2452675-159.patch12.63 KBstefdewa
#156 paragraphs-entity_translation-2452675-156.patch14.25 KBjbhovik
#147 paragraphs-entity_translation-2452675-146.patch14.25 KBgarphy
#143 paragraphs-entity_translation-2452675-143.patch1.65 KBpfenriquez
#140 paragraphs-entity_translation-2452675-140.patch15.19 KBpcoffey
#136 2452675-7.x-1.x-reroll.patch14.54 KBpol
#134 paragraphs-entity_translation-2452675-134.patch14.78 KBfeuerwagen
#131 paragraphs-entity_translation-2452675-131.patch14.97 KBpbuyle
#130 paragraphs-entity_translation-2452675-130.patch12.64 KBpbuyle
#127 paragraphs-entity_translation-2452675-127.patch13.37 KBpbuyle
#125 paragraphs-entity_translation-2452675-125.patch13.44 KBpbuyle
#122 paragraphs-entity_translation-2452675-122.patch12.94 KBbleedev
#120 interdiff.diff162 bytespol
#120 issue-2452675_2.patch13 KBpol
#119 issue-2452675.patch12.98 KBpol
#116 issue-2452675.patch12.55 KBpol
#115 issue-2452675.patch10.23 KBpol
#110 paragraphs-entity_translation-2452675-110.patch11 KBPawelR
#103 paragraphs-entity_translation-2452675-103.patch12.5 KBbleedev
#100 paragraphs-entity_translation-2452675-100.patch12.88 KBbleedev
#97 paragraphs-entity_translation-2452675-97.patch12.83 KBralkeon
#96 paragraphs-entity_translation-2452675-95.patch12.97 KBralkeon
#95 paragraphs-entity_translation-2452675-95.patch10.7 KBralkeon
#93 paragraphs-entity_translation-2452675-93.patch12.5 KBjames.williams
#93 interdiff-2452675-90-93.txt1.18 KBjames.williams
#92 paragraphs-entity_translation-2452675-92.patch12.46 KBjames.williams
#92 interdiff-2452675-90-92.txt720 bytesjames.williams
#90 paragraphs-entity_translation-2452675-90.patch12.46 KBjames.williams
paragraphs_d7_entity_translation_fix_attempt.patch4.81 KBstella
#18 paragraphs-entity_translation_support-2452675-18.patch2.93 KBliquidcms
#27 paragraphs-entity_translation_support-2452675-27.patch6.08 KBliquidcms
#29 paragraphs-entity_translation_support-2452675-29.patch7.04 KB7thkey
#37 paragraphs-entity_translation_support-2452675-37.patch8.74 KBoo0shiny
#38 paragraphs-entity_translation_support-2452675-38.patch10.55 KBal.ex
#39 paragraphs-entity_translation_support-2452675-39.patch12.06 KBsumachaa
#46 paragraphs-entity_translation_support-2452675-40.patch12.07 KBoknate
#47 paragraphs-entity_translation_support-2452675-41.patch12.69 KBoknate
#48 paragraphs-entity_translation_support-2452675-42.patch12.69 KBoknate
#52 paragraphs-entity_translation_support-2452675-52.patch11.32 KBbleedev
#53 paragraphs-entity_translation_support-2452675-53.patch11.54 KBsleepingmonk
#60 paragraphs-entity_translation_support-2452675-60.patch11.54 KBsleepingmonk
#61 paragraphs-entity_translation_support-2452675-61.patch11.54 KBsleepingmonk
#74 Screen Shot 2016-06-07 at 19.16.46.png28.8 KBparrot
#76 paragraphs-entity_translation_support-2452675-76.patch10.07 KBarnested
#77 paragraphs-entity_translation_support-2452675-77-for-7.x-1.0-rc4.patch10.56 KBarnested
#78 paragraphs-entity_translation_support-2452675-77-for-7.x-1.0-rc4.patch10.05 KBarnested
#79 paragraphs-entity_translation_support-2452675-79-for-7.x-1.0-rc4.patch9.83 KBarnested
#81 paragraphs-entity_translation_support-2452675-80-for-7.x-1.0-rc4.patch12.04 KBarnested
#81 paragraphs-entity_translation_support-2452675-80.patch12.2 KBarnested

Issue fork paragraphs-2452675

Command icon 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

ciss’s picture

Status: Needs work » Needs review
ryanoreilly’s picture

EDIT: Misread description. Disregard.

miro_dietiker’s picture

note 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.

ciss’s picture

@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.

miro_dietiker’s picture

@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.

camdarley’s picture

I'm looking after a solution for scenario B.
As Jason Dean said in #2388185: Fully support Entity Translation:

User creates an English node, and adds paragraphs: image gallery, text, video, text. Then she creates a Spanish translation of the node, and image and video paragraphs don't need to be translatable as they will be the same. But she would like to translate the two text paragraphs somewhere in the backend.

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?

liquidcms’s picture

@miro_dietiker, any progress on this? Any chance the D8 solution can be back ported to D7?

ziobudda’s picture

Any news about this topic ? It is important that this module can be work in Drupal 7. Thanks.

miro_dietiker’s picture

@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.

damienmckenna’s picture

@miro_dietiker: Are you looking for someone to comaintain the D7 version?

miro_dietiker’s picture

@DamienMcKenna i'm not even one of the maintainers. We just helped pushing the D8 port. :-)

7thkey’s picture

Hi there, any news about the entity translation support?

SoBiT’s picture

Are there any news on this topic?

mihai_brb’s picture

Title: Entity translation support for Drupal 7 version » Entity translation support for Drupal 7

I 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.

liquidcms’s picture

@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.

David Malavasi’s picture

Hi,

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.

liquidcms’s picture

This 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.

Status: Needs review » Needs work

The last submitted patch, 18: paragraphs-entity_translation_support-2452675-18.patch, failed testing.

liquidcms’s picture

issues 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)

pmusaraj’s picture

@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.

mihai_brb’s picture

@liquidcms not sure how translation delete on parent entity will work for referenced paragraph entity translations.

liquidcms’s picture

@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.

honza pobořil’s picture

Btw, 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?

mihai_brb’s picture

Just 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.

liquidcms’s picture

Status: Needs work » Needs review

this 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:

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.

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.

liquidcms’s picture

and the patch

Status: Needs review » Needs work

The last submitted patch, 27: paragraphs-entity_translation_support-2452675-27.patch, failed testing.

7thkey’s picture

Added hook_install for the paragraphs_update_7102() so new installations get the correct weight.

Fixed some non existence properties errors when creating new content.

Notice: Undefined variable: entity in paragraphs_form_alter() (line 486 of /Users/fred/Sites/drupal7/drupal/sites/all/modules/contrib/paragraphs/paragraphs.module).
Notice: Trying to get property of non-object in paragraphs_form_alter() (line 486 of/Users/fred/Sites/drupal7/drupal/sites/all/modules/contrib/paragraphs/paragraphs.module).

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.

7thkey’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 29: paragraphs-entity_translation_support-2452675-29.patch, failed testing.

liquidcms’s picture

@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?

RAFA3L’s picture

Hello, 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).

liquidcms’s picture

those 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.

sumachaa’s picture

patch #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

liquidcms’s picture

re #35 - doesn't surprise me.. unlikely something i would look at but feel free to suggest a patch.

oo0shiny’s picture

I 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.

al.ex’s picture

Here'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

  • Paragraphs 7.x-1.0-rc4
  • Entity Translation 7.x-1.0-beta4+10-dev
  • Select "Paragraphs item" as translatable entity at admin/config/regional/entity_translation
  • Enable translation for one or more fields of a paragraphs bundle

Working

  • Translating a paragraph item into different languages.
  • Translating nested paragraph items.
  • Fields in the new translation get populated with values from source language.

Todos

  • Fix: the entity holding the paragraph items must be created first without any items in order to make translation work.
  • See patch: a clean fix for the bug occurring when confirming removal of a paragraph item.
  • Making paragraph items translatable that were created after the initial entity translation has been added.
sumachaa’s picture

#38 seems to be the ideal way forward. Faced few issues, updating a latest patch

  • Updated getFormLanguage to get language from the GLOBALS. This way when a creating node for first time, the languauge is set to correctly. Since its the same used when loading the form widgets, used the same here as well. Please feel to correct if there is a better approach
  • Even though fields inside a bundle is selected as translatable, the field lables were displayed with the 'all languages' hint incorrectly. Added a fix to remove this if entity_translation is enabled for paragraphs
  • Updated README.txt to include the steps

did the testing using Entity Translation 7.x-1.0-beta4 (please let us know if this needs to be the latest dev version)

csedax90’s picture

Hello, 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:

An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /system/ajax
StatusText: n/a
ResponseText: 
ReadyState: undefined

Some has the same problem?

aruuska’s picture

I'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

apugacescu’s picture

@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.

joekers’s picture

It 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.

geertvd’s picture

Overall #38 is working pretty nice for me.

  1. +++ b/paragraphs.field_widget.inc
    @@ -453,6 +453,17 @@ function paragraphs_field_widget_form_build(&$form, &$form_state, $field, $insta
    +        // Flag the field to be processed in paragraphs_form_alter to.
    +        // avoid adding incorrect translation hints.
    +        $address = array_slice($element['#parents'], 0, -2);
    +        if (empty($form['#paragraphs_translation_fields']) || !in_array($address, $form['#paragraphs_translation_fields'])) {
    +          $form['#paragraphs_translation_fields'][] = $address;
    +        }
    
    +++ b/paragraphs.module
    @@ -1366,3 +1371,24 @@ function paragraphs_bundle_copy_info() {
    +/**
    + * Implements hook_form_alter().
    + *
    + * Checks for a value set by the embedded widget so fields are not displayed
    + * with the 'all languages' hint incorrectly.
    + */
    +function paragraphs_form_alter(&$form, &$form_state) {
    +  if (!empty($form['#paragraphs_translation_fields'])) {
    +    foreach ($form['#paragraphs_translation_fields'] as $address) {
    +      drupal_array_set_nested_value($form, array_merge($address, array('#multilingual')), TRUE);
    +    }
    +  }
    +}
    

    This assumes that all fields under the paragraph will also be translatable which is not necessarily the case.

  2. Updated getFormLanguage to get language from the GLOBALS. This way when a creating node for first time, the languauge is set to correctly. Since its the same used when loading the form widgets, used the same here as well. Please feel to correct if there is a better approach

    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.

  3. +++ b/paragraphs.field_widget.inc
    @@ -700,6 +705,16 @@ function paragraphs_field_widget_embed_validate($element, &$form_state, $complet
    +    // TODO fix this
    +    // Issue: with entity translation enabled, the paragraphs_deleteconfirm_js()
    +    // callback fails with an exception due to the missing paragraphs entity property
    +    // in the forms array. In the preceeding paragraphs_remove_js() callback
    +    // however, the property is present.
    

    Is this still an issue? I couldn't reproduce it.

sumachaa’s picture

@geertvd, re: #44

  1. This does not change the field settings, it only changes the field label (removing the "all languages" word). The issue is this label gets displayed to all fields even if the field is selected as translatable, so the better trade-off would be to remove the label to avoid confusion. btw: its the same approach done with field_collection as well
  2. works fine for me as well - since using GLOBALS; one caveat is that the language used to create the Paragraph node first time should match the site language. i.e if your site language is EN, the form language drop down should have EN also. Afterwards translating to other languages work good.
  3. not able to reproduce this issue
oknate’s picture

this update to the patch fixes issue where we might not want to pull language from $GLOBALS['language']->language.

oknate’s picture

there's a typo in this patch. How do I remove it?

oknate’s picture

Adding 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.

damienmckenna’s picture

Issue tags: +Needs tests

This needs tests.

n_e_’s picture

What'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.

bleedev’s picture

Re-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.

sleepingmonk’s picture

Updated 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.

Fidelix’s picture

Status: Needs work » Needs review

The last submitted patch, 37: paragraphs-entity_translation_support-2452675-37.patch, failed testing.

The last submitted patch, 46: paragraphs-entity_translation_support-2452675-40.patch, failed testing.

The last submitted patch, 47: paragraphs-entity_translation_support-2452675-41.patch, failed testing.

The last submitted patch, 48: paragraphs-entity_translation_support-2452675-42.patch, failed testing.

ksemihin’s picture

Hi all
Its a temporary solution for correct work with module Entity translation.

For correct work with ET module you should be apply next patches:

  1. Patch #9 for module Entity translation Link: https://www.drupal.org/node/2339315#comment-10884422
  2. Patch #53 for module Paragraphs Link: https://www.drupal.org/node/2452675#comment-10985453

After apply next diff for patch entity_translation-prepopulate-form-state-2339315-8.patch

Index: modules/contrib/entity_translation/entity_translation.module
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- modules/contrib/entity_translation/entity_translation.module	(revision )
+++ modules/contrib/entity_translation/entity_translation.module	(date 1459252422000)
@@ -1343,12 +1343,15 @@
       $langcode = $element['#language'];
       $parents = $element[$langcode]['#field_parents'];
       $source_state = field_form_get_state($source_parents, $field_name, $source, $source_form_state);
-      /* This part is specific to field collections really. */
+      /* This part is specific to field collections and paragraphs really. */
       if (isset($source_state['entity'])) {
         foreach ($source_state['entity'] as $delta => $source_state_entity) {
           if ($source_state_entity instanceof FieldCollectionItemEntity) {
             $source_state['entity'][$delta] = entity_translation_clone_entity('field_collection_item', $source_state_entity);
           }
+          if ($source_state_entity instanceof ParagraphsItemEntity) {
+            $source_state['entity'][$delta] = entity_translation_clone_entity('paragraphs_item', $source_state_entity);
+          }
         }
       }
       /* End part. */

Best regards,

sleepingmonk’s picture

Small update to patch #53 on the view method.

-     $langcode = $GLOBALS['language']->language;
+     $langcode = $GLOBALS['content_language']->language;

This is to ensure we see the content language.

However, the full conditions are:

    if ($langcode == NULL) {
      $langcode = LANGUAGE_NONE;
    }

if (module_exists('entity_translation') && entity_translation_enabled('paragraphs_item', $this->bundle)) {
+      // Force the language code to be the current language in order to display
+      // the correct language version
+      $langcode = $GLOBALS['content_language']->language;
+    }

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

sleepingmonk’s picture

Sorry, got content_language backwards. Should be language_content.

jiv_e’s picture

Me 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:

projects[entity_translation][type] = module
projects[entity_translation][download][type] = git
projects[entity_translation][download][url] = git://git.drupal.org/project/entity_translation.git
projects[entity_translation][download][branch] = 7.x-1.x
projects[entity_translation][download][revision] = "fe91ede055691a082e0dbd8b2fcf4795c810f24a"
projects[paragraphs][version] = "1.0-rc4"

You should apply these patches before this works.

projects[entity_translation][patch][] = "https://www.drupal.org/files/issues/undefined_property_menu-2511966.patch"
projects[entity_translation][patch][] = "https://bitbucket.org/!api/2.0/snippets/tierakehitys/g9kXM/c8945329eee9992c7d5d0bbabe115cc44c2dbc7e/files/et-i18n_taxonomy-1661348-24.patch"
projects[entity_translation][patch][] = "https://www.drupal.org/files/issues/entity_translation-prepopulate-form-state-2339315-8.patch"
projects[paragraphs][patch][] = "https://bitbucket.org/!api/2.0/snippets/tierakehitys/B8epy/5d975866c6bd6bd6dd5d14652e8c4ffbdc8f4d78/files/paragraphs_entity_translation_support_2452675.patch"

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.

johanvdr’s picture

@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.

jiv_e’s picture

Hi!

I'm sorry! I asked @wroxbox to add details on the applied patches, but he's obviously too busy. :)

Here!

projects[entity_translation][patch][] = "https://www.drupal.org/files/issues/undefined_property_menu-2511966.patch"
projects[entity_translation][patch][] = "https://bitbucket.org/!api/2.0/snippets/tierakehitys/g9kXM/c8945329eee9992c7d5d0bbabe115cc44c2dbc7e/files/et-i18n_taxonomy-1661348-24.patch"
projects[entity_translation][patch][] = "https://www.drupal.org/files/issues/entity_translation-prepopulate-form-state-2339315-8.patch"

I edited the original comment also.

johanvdr’s picture

@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?)

jiv_e’s picture

Sorry, 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.

johanvdr’s picture

Thank 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.

drush sql-query "DELETE FROM entity_translation WHERE entity_type = 'paragraphs_item'"

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

No need for the paragraphs translation module.
In the end I was able to fix the extra paragraphs of the translated node in the source language by (or vice versa):
* disabling language fall back (stops cloning the paragraph item to the other languages when not needed)
* disable translation on the paragraph bundle and set the fields of paragraph field as translatable.
When the node exists in only one language, the language switcher language link is disabled then (via a custom override of the language locale menu block). Instead of showing a message the translation is not available.
patch  paragraphs-entity_translation_support-2452675-53.patch 
giorgosk’s picture

tried #61 patch with instructions from #60
but when saving translated content I get this fatal error

Fatal error: Class 'EntityTranslationParagraphsItemHandler' not found in /home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/includes/translation.handler_factory.inc on line 93 Call Stack: 0.0001 237860 1. {main}() /home/drupalpro/websites/domain.dev/index.php:0 0.0492 2949052 2. menu_execute_active_handler() /home/drupalpro/websites/domain.dev/index.php:21 0.0493 2949672 3. call_user_func_array:{/home/drupalpro/websites/domain.dev/includes/menu.inc:527}() /home/drupalpro/websites/domain.dev/includes/menu.inc:527 0.0493 2950148 4. entity_translation_add_page() /home/drupalpro/websites/domain.dev/includes/menu.inc:527 0.0494 2951272 5. _entity_translation_callback() /home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/entity_translation.module:690 0.0494 2951364 6. call_user_func_array:{/home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/entity_translation.module:701}() /home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/entity_translation.module:701 0.0494 2951584 7. node_page_edit() /home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/entity_translation.module:701 0.0495 2951940 8. drupal_get_form() /home/drupalpro/websites/domain.dev/modules/node/node.pages.inc:14 0.0495 2952496 9. drupal_build_form() /home/drupalpro/websites/domain.dev/includes/form.inc:130 0.0544 4141996 10. drupal_process_form() /home/drupalpro/websites/domain.dev/includes/form.inc:385 0.3484 8590328 11. form_execute_handlers() /home/drupalpro/websites/domain.dev/includes/form.inc:903 0.3484 8594516 12. i18n_node_form_submit() /home/drupalpro/websites/domain.dev/includes/form.inc:1519 0.3555 8583756 13. node_save() /home/drupalpro/websites/domain.dev/sites/all/modules/i18n/i18n_node/i18n_node.module:467 0.3591 8600068 14. field_attach_presave() /home/drupalpro/websites/domain.dev/modules/node/node.module:1086 0.3591 8600096 15. _field_invoke() /home/drupalpro/websites/domain.dev/modules/field/field.attach.inc:914 0.3593 8602336 16. paragraphs_field_presave() /home/drupalpro/websites/domain.dev/modules/field/field.attach.inc:209 0.3593 8603004 17. ParagraphsItemEntity->save() /home/drupalpro/websites/domain.dev/sites/all/modules/paragraphs/paragraphs.module:742 0.3594 8603308 18. EntityAPIController->save() /home/drupalpro/websites/domain.dev/sites/all/modules/paragraphs/ParagraphsItemEntity.inc:406 0.3604 8603916 19. EntityAPIController->invoke() /home/drupalpro/websites/domain.dev/sites/all/modules/entity/includes/entity.controller.inc:443 0.3614 8604608 20. module_invoke_all() /home/drupalpro/websites/domain.dev/sites/all/modules/entity/includes/entity.controller.inc:355 0.3618 8606404 21. call_user_func_array:{/home/drupalpro/websites/domain.dev/includes/module.inc:951}() /home/drupalpro/websites/domain.dev/includes/module.inc:951 0.3618 8606704 22. paragraphs_entity_presave() /home/drupalpro/websites/domain.dev/includes/module.inc:951 0.3618 8606704 23. entity_translation_get_handler() /home/drupalpro/websites/domain.dev/sites/all/modules/paragraphs/paragraphs.module:1382 0.3618 8606704 24. EntityTranslationHandlerFactory->getHandler() /home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/entity_translation.module:1892

when trying to set a particular paragraphs field to "enable or disable translation" I get this

An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path: /en/batch?id=327&op=do StatusText: OK ResponseText: Fatal error: Class 'EntityTranslationParagraphsItemHandler' not found in /home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/includes/translation.handler_factory.inc on line 93 Call Stack: 0.0000 129384 1. {main}() /home/drupalpro/websites/domain.dev/index.php:0 0.0272 2506600 2. menu_execute_active_handler() /home/drupalpro/websites/domain.dev/index.php:21 0.0273 2507536 3. call_user_func_array:{/home/drupalpro/websites/domain.dev/includes/menu.inc:527}() /home/drupalpro/websites/domain.dev/includes/menu.inc:527 0.0273 2507656 4. system_batch_page() /home/drupalpro/websites/domain.dev/includes/menu.inc:527 0.0273 2507708 5. _batch_page() /home/drupalpro/websites/domain.dev/modules/system/system.admin.inc:2384 0.0274 2508160 6. _batch_do() /home/drupalpro/websites/domain.dev/includes/batch.inc:80 0.0274 2508280 7. _batch_process() /home/drupalpro/websites/domain.dev/includes/batch.inc:161 0.0288 2527316 8. call_user_func_array:{/home/drupalpro/websites/domain.dev/includes/batch.inc:284}() /home/drupalpro/websites/domain.dev/includes/batch.inc:284 0.0288 2527508 9. entity_translation_translatable_batch() /home/drupalpro/websites/domain.dev/includes/batch.inc:284 0.0424 2937892 10. entity_translation_get_handler() /home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/entity_translation.admin.inc:580 0.0424 2940896 11. EntityTranslationHandlerFactory->getHandler() /home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/entity_translation.module:1892

I had paragraph field not translatable when I try to enable translation for it I get

An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path: /en/batch?id=328&op=do StatusText: OK ResponseText: Fatal error: Class 'EntityTranslationParagraphsItemHandler' not found in /home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/includes/translation.handler_factory.inc on line 93 Call Stack: 0.0000 129384 1. {main}() /home/drupalpro/websites/domain.dev/index.php:0 0.0261 2506748 2. menu_execute_active_handler() /home/drupalpro/websites/domain.dev/index.php:21 0.0262 2507684 3. call_user_func_array:{/home/drupalpro/websites/domain.dev/includes/menu.inc:527}() /home/drupalpro/websites/domain.dev/includes/menu.inc:527 0.0262 2507804 4. system_batch_page() /home/drupalpro/websites/domain.dev/includes/menu.inc:527 0.0262 2507856 5. _batch_page() /home/drupalpro/websites/domain.dev/modules/system/system.admin.inc:2384 0.0262 2508308 6. _batch_do() /home/drupalpro/websites/domain.dev/includes/batch.inc:80 0.0262 2508428 7. _batch_process() /home/drupalpro/websites/domain.dev/includes/batch.inc:161 0.1278 4081816 8. call_user_func_array:{/home/drupalpro/websites/domain.dev/includes/batch.inc:284}() /home/drupalpro/websites/domain.dev/includes/batch.inc:284 0.1278 4082008 9. entity_translation_translatable_batch() /home/drupalpro/websites/domain.dev/includes/batch.inc:284 0.1781 4460192 10. _entity_translation_update_field() /home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/entity_translation.admin.inc:610 0.1782 4461272 11. field_attach_presave() /home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/entity_translation.admin.inc:657 0.1782 4461340 12. _field_invoke() /home/drupalpro/websites/domain.dev/modules/field/field.attach.inc:914 0.1783 4463668 13. paragraphs_field_presave() /home/drupalpro/websites/domain.dev/modules/field/field.attach.inc:209 0.1919 4612460 14. ParagraphsItemEntity->save() /home/drupalpro/websites/domain.dev/sites/all/modules/paragraphs/paragraphs.module:742 0.1919 4612764 15. EntityAPIController->save() /home/drupalpro/websites/domain.dev/sites/all/modules/paragraphs/ParagraphsItemEntity.inc:406 0.1980 4619432 16. EntityAPIController->invoke() /home/drupalpro/websites/domain.dev/sites/all/modules/entity/includes/entity.controller.inc:443 0.1991 4620124 17. module_invoke_all() /home/drupalpro/websites/domain.dev/sites/all/modules/entity/includes/entity.controller.inc:355 0.1996 4621916 18. call_user_func_array:{/home/drupalpro/websites/domain.dev/includes/module.inc:951}() /home/drupalpro/websites/domain.dev/includes/module.inc:951 0.1996 4622216 19. paragraphs_entity_presave() /home/drupalpro/websites/domain.dev/includes/module.inc:951 0.1996 4622216 20. entity_translation_get_handler() /home/drupalpro/websites/domain.dev/sites/all/modules/paragraphs/paragraphs.module:1382 0.1996 4622216 21. EntityTranslationHandlerFactory->getHandler() /home/drupalpro/websites/domain.dev/sites/all/modules/entity_translation/entity_translation.module:1892
jiv_e’s picture

@johanvdr Sorry for the inconvenience! I edited the original comment and added the details there. See: https://www.drupal.org/node/2452675#comment-11082609

giorgosk’s picture

Followed instructions from #62

following patch has a warning
https://bitbucket.org/!api/2.0/snippets/tierakehitys/g9kXM/c8945329eee99...

Checking patch entity_translation.admin.inc...
Checking patch entity_translation.module...
Checking patch entity_translation.node.inc...
Checking patch entity_translation.taxonomy.inc...
b.patch:232: new blank line at EOF.
+
Checking patch includes/translation.handler.taxonomy_term.inc...
Applied patch entity_translation.admin.inc cleanly.
Applied patch entity_translation.module cleanly.
Applied patch entity_translation.node.inc cleanly.
Applied patch entity_translation.taxonomy.inc cleanly.
Applied patch includes/translation.handler.taxonomy_term.inc cleanly.
warning: 1 line adds whitespace errors.

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)

Tronux’s picture

I 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.

// Paragraphs render fix
    foreach ($content['field_page_layout']['#object']->field_page_layout[$GLOBALS['language']->language] as $paragraph){
        $paragraphEntity = entity_load("paragraphs_item",array($paragraph['value']));
        //Per Paragraph field on the page-node get a renderable array of fields!
        $renderableParagraphBundle = field_attach_view("paragraphs_item", $paragraphEntity[$paragraph['value']], "full", $langcode = $GLOBALS['language']->language, $options = array());
        print render($renderableParagraphBundle);
    }

Hope I helped,
- thomas_vc

leo_li’s picture

@GiorgosK

I got the same problem when deleting the translated paragraph, after applying @jiv_e 's patch in #62

leo_li’s picture

@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:

/*
    else {
      $row = db_select('paragraphs_item_revision', 'r')
        ->fields('r')
        ->condition('item_id', $this->item_id)
        ->condition('revision_id', $this->revision_id, '<>')
        ->execute()
        ->fetchAssoc();
      // If no other revision is left, delete. Else archive the item.
      if (!$row) {
        $this->delete();
      }
      else {
        // Make the other revision the default revision and archive the item.
        db_update('paragraphs_item')
          ->fields(array('archived' => 1, 'revision_id' => $row['revision_id']))
          ->condition('item_id', $this->item_id)
          ->execute();
        entity_get_controller('paragraphs_item')->resetCache(array($this->item_id));
        entity_revision_delete('paragraphs_item', $this->revision_id);
      }
    }
    */

At least, it works for me. Hope it helps for you too.

parrot’s picture

StatusFileSize
new28.8 KB

Problem with paragraphs inside taxonomy term.
exception
breaks at entity_save($term).

7thkey’s picture

Status: Needs review » Needs work

Still needs work...

arnested’s picture

I 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).

arnested’s picture

Add a version of the patch from #76 but rerolled against current release 7.x-1.0-rc4.

PATCH HAS WRONG PATCH LEVEL.

arnested’s picture

And the version of the 7.x-1.0-rc4 reroll with the correct patch level.

PATCH HAS WRONG PATCH LEVEL.

arnested’s picture

This time it should be with the right patch level. Sorry for the noise.

edi44’s picture

Patch #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

arnested’s picture

OK, 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.

edi44’s picture

Thank you very much! 7.x-1.x-dev + patch#80 is working very well :)

damienmckenna’s picture

Status: Needs work » Needs review

Changing status to "needs review" so the testbot does its thing.

I still think there ought to be tests for this.

sitiveni’s picture

Hi 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.

  public function __construct($entity_type, $entity_info, $entity) {
    if (method_exists($entity, 'hostEntity')) {
      $this->hostEntity = $entity->hostEntity();
      $host_entity_type = (isset($this->hostEntity->type)) ? 'node' : 'paragraphs_item';
      if ($host_entity_type == 'paragraphs_item') {// A nested paragraphs field
        // Look for the parent host entity
        while (method_exists($this->hostEntity, 'hostEntity')) {
          $this->hostEntity = $this->hostEntity->hostEntity();
        }
      }

      $this->hostEntityHandler = entity_translation_get_handler('node', $this->hostEntity);
    }
    parent::__construct('paragraphs_item', $entity_info, $entity);
  }

What if you'd replace 'node' with $entity->hostEntityType()? Would that work?

sitiveni’s picture

To tie in with my comment above, here's an idea how to use $entity->hostEntityType() instead of hard coded 'node':

  public function __construct($entity_type, $entity_info, $entity) {
    if (method_exists($entity, 'hostEntity') && $this->hostEntity = $entity->hostEntity()) {
      $host_entity_type = !empty($entity->hostEntityType()) ? $entity->hostEntityType() : 'paragraphs_item';
      if ($host_entity_type == 'paragraphs_item') {// A nested paragraphs field
        // Look for the parent host entity
        while (method_exists($this->hostEntity, 'hostEntity')) {
          $this->hostEntity = $this->hostEntity->hostEntity();
        }
      }

      $this->hostEntityHandler = entity_translation_get_handler($entity->hostEntityType(), $this->hostEntity);
    }
    parent::__construct('paragraphs_item', $entity_info, $entity);
  }

Also note that the host entity needs to be available to proceed.

RAFA3L’s picture

Thanks! #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?

RAFA3L’s picture

Sorry, I was making the paragraph field translatable and not the fields inside. Now all the shared fields are synchronized, perfect!

RAFA3L’s picture

Hello 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

james.williams’s picture

Here's a re-rolled patch that includes something based on the suggestion from comment 86 above.

titouille’s picture

Hi,

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:

An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /system/ajax
StatusText: n/a
ResponseText: 
( ! ) Fatal error: Call to undefined method stdClass::hostEntityType() in /sites/all/modules/contrib/paragraphs/includes/translation.handler.paragraphs_item.inc on line 29

When I see the code on translation handler :

     // A nested paragraphs field.
      if ($host_entity_type == 'paragraphs_item') {
        // Look for the parent host entity.
        while (method_exists($this->hostEntity, 'hostEntity')) {
            $this->hostEntity = $this->hostEntity->hostEntity();
            $host_entity_type = $this->hostEntity->hostEntityType();
        }
      }

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:

        while (method_exists($this->hostEntity, 'hostEntity')) {
          if ($this->hostEntity->hostEntityType() == 'paragraphs_item') {
            $this->hostEntity = $this->hostEntity->hostEntity();
            $host_entity_type = $this->hostEntity->hostEntityType();
          }
          else {
            break;
          }
        }

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 ?

james.williams’s picture

StatusFileSize
new720 bytes
new12.46 KB

Sorry, 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.

james.williams’s picture

StatusFileSize
new1.18 KB
new12.5 KB

Argh, just spotted a PHP warning that would be thrown. So ignore my last comment! Try again...

Status: Needs review » Needs work

The last submitted patch, 93: paragraphs-entity_translation-2452675-93.patch, failed testing.

ralkeon’s picture

Hi 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.

ralkeon’s picture

StatusFileSize
new12.97 KB

Sorry forgot to include translation.handler.paragraphs_item.inc in the patch. Here it is.

ralkeon’s picture

StatusFileSize
new12.83 KB

Hi all, I faced the last issue again while using nested paragraphs, I tried to fix it, hope it helps and it works!

idebr’s picture

Status: Needs work » Needs review
jbhovik’s picture

Hi 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.

bleedev’s picture

Found an error using nested paragraphs in #97

Updated patch attached.

Status: Needs review » Needs work

The last submitted patch, 100: paragraphs-entity_translation-2452675-100.patch, failed testing.

proweb.ua’s picture

after 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

bleedev’s picture

Fix bug causing incorrect language in translated paragraph fields.

sleepingmonk’s picture

@proweb.ua
Try registry rebuild with drush rr.
You may need to install registry_rebuild first: drush dl registry_rebuild

proweb.ua’s picture

@bleedev, thanks
#103 works

amme’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 103: paragraphs-entity_translation-2452675-103.patch, failed testing.

RAFA3L’s picture

Trying #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.

bwoods’s picture

I 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.

PawelR’s picture

Status: Needs work » Needs review
StatusFileSize
new11 KB

I'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():

if (module_exists('i18n')) {
  $content_language = i18n_language_content();
  $language = $content_language->language;
}

to this:

if (module_exists('entity_translation') && entity_translation_enabled('paragraphs_item', $paragraph_item->bundle)) {
  $language = entity_language('node', $form['#entity']);
}

Status: Needs review » Needs work

The last submitted patch, 110: paragraphs-entity_translation-2452675-110.patch, failed testing.

pivica’s picture

To @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.

teknocat’s picture

I 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.

pol’s picture

@PawelR: your last patch is incomplete.

@bleedev: Patch from #103 is working flawlessly with latest dev version of paragraphs. THANKS !!!

pol’s picture

StatusFileSize
new10.23 KB

Here's an updated patch.

pol’s picture

StatusFileSize
new12.55 KB

Sorry last patch is not good, there are missing files.

Here the good one.

amme’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 116: issue-2452675.patch, failed testing.

pol’s picture

Status: Needs work » Needs review
StatusFileSize
new12.98 KB
pol’s picture

StatusFileSize
new13 KB
new162 bytes

Hi 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.

pol’s picture

Hi all,

The patch I submitted in #120 has a slight problem.

When I create a Fieldable Panels Pane(FPP) containing paragraphs, the variable $langcode passed 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.

bleedev’s picture

Re-rolled #103 with update from https://www.drupal.org/node/2831973

Status: Needs review » Needs work

The last submitted patch, 122: paragraphs-entity_translation-2452675-122.patch, failed testing.

pol’s picture

Status: Needs work » Active

@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:

      // Set the form language to the current language for translation.
      if (module_exists('entity_translation') && entity_translation_enabled('paragraphs_item', $paragraph_item->bundle)) {
        $language = entity_language($instance['entity_type'], $form['#entity']);
      }
      else {
        $language = $GLOBALS['language']->language;
      }

Instead of

      // Set the form language to the current language for translation.
      if (module_exists('i18n')) {
        $content_language = i18n_language_content();
        $language = $content_language->language;
      }
      else {
        $language = $GLOBALS['language']->language;
      }
pbuyle’s picture

Here 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.

pbuyle’s picture

My latest patch in #125 does not include support for non-node host entities as mentioned by @Pol in #124.

pbuyle’s picture

And here is the updated patch:

In initial testing, I was able to create a content with three levels on nested paragraphs and translate them.

pbuyle’s picture

I got mixed up please disregard comments #126 and #127.

pbuyle’s picture

pbuyle’s picture

When 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, the form['#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.

pbuyle’s picture

StatusFileSize
new14.97 KB

Patch in #130 is broken, here is the correct one.

pol’s picture

Status: Active » Reviewed & tested by the community

Dear @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 :(

maico de jong’s picture

Status: Reviewed & tested by the community » Needs work

#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.

feuerwagen’s picture

Rerolled #131 based on current 7.x-1.x-dev branch.

pol’s picture

Hi Feuerwagen,

Your patch doesn't apply.

pol’s picture

StatusFileSize
new14.54 KB

Here's an updated patch.

badrange’s picture

Heads up; this thing just got committed to Entity Translation - it may affect this patch:
https://www.drupal.org/node/2849464

fadeslayer’s picture

version = "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

global $language_content;
$langcodecontent = $language_content->language;

and modifying entity view call as

$element[$delta]['entity'] = $paragraph->view($view_mode,$langcodecontent);

(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.

pol’s picture

#136 needs to be rewritten using new Entity Translation API.(see change record)

I will try to do it this week.

pcoffey’s picture

Hey 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!

bwoods’s picture

I've just started testing and making edits, but so far, #140 is working for me. Thanks!

guillaumeduveau’s picture

It 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 :

Error : Class 'EntityTranslationParagraphsItemHandler' not found dans EntityTranslationHandlerFactory->getHandler() (ligne 93 dans /www/sites/all/modules/entity_translation/includes/translation.handler_factory.inc).
pfenriquez’s picture

I 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.

pol’s picture

Are you sure that your patch is complete ?

Tips: use git diff --cached to create your patch.

pfenriquez’s picture

Sorry, I pushed only the patch for the rejected part. I try to add the complete patch as soon as I can.

garphy’s picture

Status: Needs work » Needs review

Here is a reroll of #140

garphy’s picture

Better with the patch file...

The last submitted patch, 134: paragraphs-entity_translation-2452675-134.patch, failed testing. View results

The last submitted patch, 140: paragraphs-entity_translation-2452675-140.patch, failed testing. View results

The last submitted patch, 143: paragraphs-entity_translation-2452675-143.patch, failed testing. View results

RAFA3L’s picture

Working 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.

howdytom’s picture

#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

ciss’s picture

Status: Needs review » Needs work
+++ b/ParagraphsItemEntity.inc
@@ -514,6 +514,12 @@ class ParagraphsItemEntity extends Entity {
+    if (module_exists('entity_translation') && entity_translation_enabled('paragraphs_item', $this->bundle)) {

This 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

ciss’s picture

+++ b/includes/translation.handler.paragraphs_item.inc
@@ -0,0 +1,64 @@
+  public function getFormLanguage() {

Deprecated 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.

ciss’s picture

+++ b/includes/translation.handler.paragraphs_item.inc
@@ -0,0 +1,64 @@
+      $this->hostEntityHandler = entity_translation_get_handler($host_entity_type, $this->hostEntity);

This line should read:

      if (!empty($this->hostEntity)) {
        $this->hostEntityHandler = entity_translation_get_handler($host_entity_type, $this->hostEntity);
      }

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.

jbhovik’s picture

Hi 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.

Jack0140’s picture

Hi 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.

RAFA3L’s picture

Yes 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

/**
 * Implements hook_entity_insert().
 */
function MODULE_entity_insert($entity, $type) {
  if ($type == 'paragraphs_item') {
    _MODULE_process($entity, $type);
  }
}

/**
 * Translate fields inside paragraphs item
 */
function _MODULE_process($entity, $type) {

  $languages = array_keys(language_list());
  $values = array();
  $default_lang = language_default();
  $source = $default_lang->language;
  $handler = entity_translation_get_handler('paragraphs_item', $entity, TRUE);

  if(($key = array_search($source, $languages)) !== false) {
    unset($languages[$key]);
  }

  foreach ($languages as $langcode) {

    $translation = array(
      'translate' => 0,
      'status'    => 1,
      'language'  => $langcode,
      'source'    => $source,
    );

    foreach (field_info_instances('paragraphs_item', $entity->bundle) as $instance) {

      $field_name = $instance['field_name'];
      $field = field_info_field($field_name);

      if ($field['translatable']) {
        $value = $entity->{$field_name}[key($entity->{$field_name})];
        $values[$field_name][$langcode] = $value;
        $entity->{$field_name}[$langcode] = $value;

        $handler->setTranslation($translation, $values);
        $handler->saveTranslations();

        field_attach_update('paragraphs_item', $entity);
      }
    }
  }
}

/**
 * Implements hook_entity_delete().
 */
function MODULE_entity_delete($entity, $type) {
  if ($type == 'paragraphs_item') {
    foreach (array('entity_translation', 'entity_translation_revision') as $table) {
      $res = db_delete($table)
        ->condition('entity_type', $type)
        ->condition('entity_id', $entity->item_id)
        ->execute();
    }
  }
}
stefdewa’s picture

Rerolled #156 against 7.x-1.0-rc5.

ciss’s picture

@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.

jbhovik’s picture

@ciss, I based my patch on paragraphs-entity_translation-2452675-146.patch. I changed only one line from "'language' => 'langcode'," to "'language' => 'language',"

codium’s picture

@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.

RAFA3L’s picture

@codium this is because at the moment of the paragraph creation the fields inside are not properly translated, see #158

a65162’s picture

I applied #156 patch, but there printed an error message

Fatal error: Class 'EntityTranslationParagraphsItemHandler' not found in .../modules/contrib/entity_translation/includes/translation.handler_factory.inc on line 93
ReadyState: undefined

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.

ciss’s picture

I propose we change the entity key from "langcode" to "language" for paragraphs items.

@jbhovik What implications does this change have? Will it break existing sites that already have #147 applied?

+++ b/includes/translation.handler.paragraphs_item.inc
@@ -0,0 +1,64 @@
+  public function getTranslations() {
+    return $this->hostEntityHandler ? $this->hostEntityHandler->getTranslations() : parent::getTranslations();
+  }

This breaks hook_entity_translation_insert() for nodes:

  1. The method may return the translations property 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.
  2. When saving a translation, entity_translation modifies the "hook" information in the translations object. By default the hook will be set to "insert". This string determines wether hook_entity_translation_insert() or hook_entity_translation_update() will be invoked.
  3. When it's time to save the node's translation, the hook information is missing and defaults to "update". This causes entity_translation to invoke the wrong hook.
jbhovik’s picture

@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.

ciss’s picture

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 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.

james.williams’s picture

@ciss That's really well put, I'd totally agree. I was a bit worried seeing this back & forth about the extra unnecessary change.

mlanth’s picture

Update 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.

codium’s picture

Status: Needs work » Needs review
StatusFileSize
new7.83 KB

My 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!

Status: Needs review » Needs work

The last submitted patch, 170: paragraphs-entity_translation-2452675-170.patch, failed testing. View results

codium’s picture

Status: Needs work » Needs review
codium’s picture

Added patch #146 into #170

Status: Needs review » Needs work

The last submitted patch, 173: paragraphs-entity_translation-2452675-173.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

codium’s picture

codium’s picture

codium’s picture

codium’s picture

StatusFileSize
new20.14 KB
codium’s picture

StatusFileSize
new20.57 KB
codium’s picture

Status: Needs work » Needs review
tinli’s picture

Hi,
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.

if(isset($hostEntity->original)){
        $old_source_language = $hostEntity->original->language;
      }else{
        $old_source_language = '';
      }

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

codium’s picture

@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.

codium’s picture

@tinli since tests passed here can you test it more? Especially case with nested paragraphs.

pol’s picture

Hello,

I just did a quick code review on the style.

  1. +++ b/ParagraphsItemEntity.inc
    @@ -399,6 +401,91 @@ class ParagraphsItemEntity extends Entity {
    +      $field_names = array_keys(field_info_instances($this->entityType(), $this->bundle()));
    

    This line is too long and can be split in multiple lines. (multiple places)

  2. +++ b/ParagraphsItemEntity.inc
    @@ -399,6 +401,91 @@ class ParagraphsItemEntity extends Entity {
    +          if ($field_language <> $host_language) {
    

    use !== instead of <> (multiple places)

  3. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,120 @@
    +
    

    Empty line not needed. (multiple places)

  4. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,120 @@
    +    // Avoid content deletion when user change language on untranslated node.
    

    I would separate with an empty line code paragraphs with a comment.

  5. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,120 @@
    +      unset($originalTranslation['entity_id']);
    +      unset($originalTranslation['revision_id']);
    

    I would group those two unset in one:

    unset($a, $b);
    
  6. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,120 @@
    +  public function getLanguage() {
    

    Do you think it would be possible to add the documentation header of each method and the proper return type?

  7. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,120 @@
    +    return $this->hostEntityHandler ? $this->hostEntityHandler->getLanguage() : parent::getLanguage();
    

    This line is too long and can be split.

    return $this->hostEntityHandler ?
      $this->hostEntityHandler->getLanguage() :
      parent::getLanguage();
    
    
  8. +++ b/paragraphs.field_widget.inc
    @@ -698,6 +721,17 @@ function paragraphs_field_widget_embed_validate($element, &$form_state, $complet
    +    if ($element['#entity_type'] != 'paragraphs_item') {
    

    I would use !== as much as possible.

  9. +++ b/paragraphs.module
    @@ -860,6 +881,40 @@ function paragraphs_field_delete_revision($entity_type, $entity, $field, $instan
    +  if (isset($field_state['entity'])) {
    

    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.

    if (!isset($field_state['entity'])) {
      return;
    }
    
    // main code here
    
    
  10. +++ b/paragraphs.module
    @@ -1398,6 +1399,40 @@ function paragraphs_features_api() {
    +  if (!empty($form['#paragraphs_translation_fields'])) {
    

    I would move the main code out of the if and use an early return.

  11. +++ b/paragraphs.module
    @@ -1398,6 +1399,40 @@ function paragraphs_features_api() {
    +  if ($type == 'paragraphs_item' && module_exists('entity_translation')) {
    

    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!

codium’s picture

Thanks a lot @pol for support. I think I've fixed most of it. I'm not sure about whole documentation changes inEntityTranslationParagraphsItemHandler class, 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!

codium’s picture

StatusFileSize
new14.48 MB

Beside 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:

Exception: Cannot initialize entity translation path variables (invalid path scheme). in EntityTranslationDefaultHandler->initPathVariables() (line 1737 of /var/www/drupalvm/drupal/web/sites/all/modules/contrib/entity_translation/includes/translation.handler.inc).

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.

Status: Needs review » Needs work

The last submitted patch, 185: paragraphs-entity_translation-2452675-185.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

codium’s picture

codium’s picture

Status: Needs work » Needs review
codium’s picture

pol’s picture

Hi,

Thanks for the fixes, I did another review.

  1. +++ b/ParagraphsItemEntity.inc
    @@ -399,6 +401,95 @@ class ParagraphsItemEntity extends Entity {
    +          $field_language = field_language($this->entityType(), $this, $field_name);
    

    Split into multi-line.

  2. +++ b/ParagraphsItemEntity.inc
    @@ -424,7 +515,7 @@ class ParagraphsItemEntity extends Entity {
    +        $host_entity->{$this->field_name}[$this->langcode][] = array('entity' => $this);
    

    This should be on multi-line as well.

  3. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,165 @@
    +      parent::__construct('paragraphs_item', $entity_info, $entity);
    

    Does this mean that parent constructor could be called twice then?

  4. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,165 @@
    +      if ($host_entity_type == 'paragraphs_item') {
    

    use ===

  5. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,165 @@
    +      $this->hostEntityHandler = entity_translation_get_handler($host_entity_type, $this->hostEntity);
    

    Split into multi-line.

  6. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,165 @@
    +    return $this->hostEntityHandler ? $this->hostEntityHandler->getLanguage()
    +      : parent::getLanguage();
    

    Even if this is technically perfectly valid, I would do this on 3 lines instead of two for readability.

  7. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,165 @@
    +    return $this->hostEntityHandler ? $this->hostEntityHandler->getFormLanguage()
    +      : parent::getFormLanguage();
    

    Same here.

  8. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,165 @@
    +    return $this->hostEntityHandler ?
    +      $this->hostEntityHandler->getSourceLanguage() :
    +      parent::getSourceLanguage();
    

    This is perfect.

  9. +++ b/paragraphs.field_widget.inc
    @@ -406,7 +412,7 @@ function paragraphs_field_widget_form_build(&$form, &$form_state, $field, $insta
    +    $paragraph_item->setHostEntity($element['#host_entity_type'], $element['#host_entity'], $langcode, FALSE);
    

    Split into multi-line.

  10. +++ b/paragraphs.field_widget.inc
    @@ -425,7 +431,7 @@ function paragraphs_field_widget_form_build(&$form, &$form_state, $field, $insta
    +      $paragraph_item->setHostEntity($element['#host_entity_type'], $element['#host_entity'], $langcode, FALSE);
    

    Split into multi-line.

  11. +++ b/paragraphs.field_widget.inc
    @@ -457,6 +463,23 @@ function paragraphs_field_widget_form_build(&$form, &$form_state, $field, $insta
    +      if (module_exists('entity_translation') && entity_translation_enabled('paragraphs_item', $paragraph_item->bundle)) {
    ...
    +      if (module_exists('entity_translation') && entity_translation_enabled('paragraphs_item', $paragraph_item->bundle)) {
    

    These are the same conditions and can be simplified.

    First, check if the module exists.
    Then inside that first condition, add the other conditions.

  12. +++ b/paragraphs.module
    @@ -851,11 +872,47 @@ function paragraphs_field_delete($entity_type, $entity, $field, $instance, $lang
    +  if ($entity_type != 'paragraphs_item') {
    

    use !==

  13. +++ b/paragraphs.module
    @@ -851,11 +872,47 @@ function paragraphs_field_delete($entity_type, $entity, $field, $instance, $lang
    +  if (isset($field_state['entity'])) {
    

    Use the inverse condition and use early return here as well.

    if (!isset($field_state['entity'])) {
      return;
    }
    
  14. +++ b/paragraphs.module
    @@ -1398,6 +1401,46 @@ function paragraphs_features_api() {
    +  if ($type !== 'paragraphs_item' || !module_exists('entity_translation')) {
    

    I would invert the condition. First check if the module exists (or not), then check the type.

codium’s picture

Thanks @pol, patch updated.

pol’s picture

Hello,

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!

  1. +++ b/ParagraphsItemEntity.inc
    @@ -399,6 +401,95 @@ class ParagraphsItemEntity extends Entity {
    +        if (isset($field['translatable']) && $field['translatable']) {
    

    We could simplify the foreach and use the inverted condition here.

    $field += array('translatable' => FALSE);
    if ($field['translatable'] === FALSE) {
      continue;
    }
    
    // Main foreach code here.
    
    
  2. +++ b/ParagraphsItemEntity.inc
    @@ -514,6 +607,16 @@ class ParagraphsItemEntity extends Entity {
    +      global $language_content;
    

    I think it would be better to use the $GLOBALS variable.

  3. +++ b/ParagraphsItemEntity.inc
    @@ -564,4 +667,16 @@ class ParagraphsItemEntity extends Entity {
    +    return array_keys($instances);
    

    Always have an empty line before the return statement.

  4. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,168 @@
    +      parent::__construct('paragraphs_item', $entity_info, $entity);
    

    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.

  5. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,168 @@
    +      if ($activeLanguage == LANGUAGE_NONE &&
    

    Use ===

  6. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,168 @@
    +        unset($originalTranslation['entity_id'], $originalTranslation['revision_id']);
    

    Split this into 2 lines.

  7. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,168 @@
    +    return $this->hostEntityHandler ? $this->hostEntityHandler->getLanguage()
    

    Let's be consistent and use 3 lines instead of 2. Just like you did after.

  8. +++ b/paragraphs.module
    @@ -1398,6 +1408,47 @@ function paragraphs_features_api() {
    +    drupal_array_set_nested_value($form, array_merge($address, array('#multilingual')), TRUE);
    

    The line is longer than 80 chars. Please split the line.

  9. +++ b/paragraphs.module
    @@ -1398,6 +1408,47 @@ function paragraphs_features_api() {
    +    $et_handler->setOriginalLanguage($et_handler->hostEntityHandler->getLanguage());
    

    The line is longer than 80 chars. Please split the line.

codium’s picture

@pol thanks for the patient, another update

pol’s picture

Status: Needs review » Needs work

Hello,

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!

  1. +++ b/ParagraphsItemEntity.inc
    @@ -102,25 +102,29 @@ class ParagraphsItemEntity extends Entity {
    +
    

    Please, remove any empty line after the start of the function.

  2. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,172 @@
    +
    

    Extra empty line.

  3. +++ b/includes/translation.handler.paragraphs_item.inc
    @@ -0,0 +1,172 @@
    +      parent::__construct('paragraphs_item', $entity_info, $entity);
    

    Still the same issue. If the module entity_translation doesn't exists, then, the parent class constructor is called twice on the same parameters.

  4. +++ b/paragraphs.field_widget.inc
    @@ -457,6 +471,26 @@ function paragraphs_field_widget_form_build(&$form, &$form_state, $field, $insta
    +        if (empty($form['#paragraphs_translation_fields']) || !in_array($address, $form['#paragraphs_translation_fields'])) {
    ...
    +        $language = entity_language($element['#host_entity_type'], $element['#host_entity']);
    

    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

  5. +++ b/paragraphs.module
    @@ -1398,6 +1408,49 @@ function paragraphs_features_api() {
    +  return "";
    

    Use single quotes.

  6. +++ b/paragraphs.module
    @@ -1398,6 +1408,49 @@ function paragraphs_features_api() {
    +    $merged = array_merge($address, array('#multilingual'));
    

    I would not create the $merged variable.

    I would write this:

    drupal_array_set_nested_value(
      $form,
      array_merge($address, array('#multilingual')),
      TRUE
    );
    
  7. +++ b/paragraphs.module
    @@ -1398,6 +1408,49 @@ function paragraphs_features_api() {
    +    $et_handler->hostEntityHandler->getLanguage() != LANGUAGE_NONE)
    

    Use !==

codium’s picture

@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:

class EntityTranslationParagraphsItemHandler {

     public function __construct($entity_type, $entity_info, $entity) {
       if (!module_exists('entity_translation')) {
         parent::__construct('paragraphs_item', $entity_info, $entity);
       } else {
         // Other code.
         parent::__construct('paragraphs_item', $entity_info, $entity);    
       } 
    }
}

I don't see the issue (call parent more than once) in the code.

codium’s picture

Final patch from my side, I've no time to fix more code formatting things.

codium’s picture

Status: Needs work » Needs review
pol’s picture

Hello,

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!

codium’s picture

@pot thanks a lot for support.

zestagio’s picture

Hello,

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...). $translations is 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.

pol’s picture

Hello,

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!

zestagio’s picture

StatusFileSize
new27.4 KB
new794 bytes

Patch 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:

  1. @@ -811,7 +832,7 @@ function paragraphs_field_update($entity_type, $entity, $field, $instance, $lang
      * Implements hook_field_delete().
      */
     function paragraphs_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {
    -  if ($field['type'] == 'paragraphs') {
    +  if ($field['type'] === 'paragraphs') {
    
  2. @@ -849,17 +870,61 @@ function paragraphs_field_delete($entity_type, $entity, $field, $instance, $lang
      * Implements hook_field_delete_revision().
      */
     function paragraphs_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) {
    -  if ($field['type'] == 'paragraphs') {
    +  if ($field['type'] === 'paragraphs') {
         foreach ($items as $item) {
    -      if (!empty($item['revision_id'])) {
    -        if ($paragraphs_item = paragraphs_item_revision_load($item['revision_id'])) {
    -          $paragraphs_item->setHostEntity($entity_type, $entity, $langcode, FALSE);
    -          $paragraphs_item->deleteRevision(TRUE);
    -        }
    +      if (!isset($item['revision_id']) || empty($item['revision_id'])) {
    +        continue;
    +      }
    +
    +      if ($paragraphs_item = paragraphs_item_revision_load($item['revision_id'])) {
    +        $paragraphs_item->setHostEntity(
    +          $entity_type,
    +          $entity,
    +          $langcode,
    +          FALSE);
    +
    +        $paragraphs_item->deleteRevision(TRUE);
    
codium’s picture

@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:

  public function getTranslations() {
    if ($this->hostEntityHandler) {
      return clone $this->hostEntityHandler->getTranslations();
    }
    return clone parent::getTranslations();
  }

Btw can you explain purpose of cloning more to me?

zestagio’s picture

@codium,

see #2452675-201: Entity translation support for Drupal 7. I described a problem there.

codium’s picture

@zestagio, got it. Thanks

RAFA3L’s picture

All 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.

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).

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

RAFA3L’s picture

Sorry, 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).

RAFA3L’s picture

Sorry 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:

/**
 * Implements hook_entity_delete().
 */
function paragraphs_entity_delete($entity, $type) {
  if ($type == 'paragraphs_item') {
    foreach (array('entity_translation', 'entity_translation_revision') as $table) {
      $res = db_delete($table)
        ->condition('entity_type', $type)
        ->condition('entity_id', $entity->item_id)
        ->execute();
    }
  }
}
RAFA3L’s picture

Problem 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

codium’s picture

@RAFA3L do you have paragraph reference field translatable or not?

RAFA3L’s picture

Not, the paragraph field in node is not translatable and fields inside paragraph are translatable

codium’s picture

@RAFA3L then please send me feature with your content type or/and verification steps (problem 3).

RAFA3L’s picture

paragraphs 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

codium’s picture

@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?

RAFA3L’s picture

Ok, 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.

RAFA3L’s picture

Sorry, 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

zestagio’s picture

StatusFileSize
new27.44 KB
new1.48 KB

Sorry 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 &&

I 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'] = 0

RAFA3L’s picture

Hello @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

zestagio’s picture

@codium, @Pol

Can someone explain what is reason to use if (!module_exists('entity_translation')) { inside __construct method?

diff --git a/includes/translation.handler.paragraphs_item.inc b/includes/translation.handler.paragraphs_item.inc
new file mode 100644
index 0000000..d2b8d3c
--- /dev/null
+++ b/includes/translation.handler.paragraphs_item.inc
@@ -0,0 +1,172 @@
+<?php
+
+/**
+ * @file
+ * Paragraphs item translation handler for the entity translation module.
+ */
+
+/**
+ * Paragraphs item translation handler.
+ *
+ * Overrides default behaviours for Paragraphs item properties.
+ */
+class EntityTranslationParagraphsItemHandler extends EntityTranslationDefaultHandler {
+
+  public $hostEntity;
+
+  public $hostEntityHandler;
+
+  /**
+   * @inheritdoc
+   */
+  public function __construct($entity_type, $entity_info, $entity) {
+    if (!module_exists('entity_translation')) {
+      parent::__construct('paragraphs_item', $entity_info, $entity);
+    }
+    else {

You already extend class EntityTranslationDefaultHandler provided 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 :(

dan.ashdown’s picture

Just 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.

RAFA3L’s picture

StatusFileSize
new28.44 KB

@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

dan.ashdown’s picture

@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.

codium’s picture

@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.

dan.ashdown’s picture

Thanks @codium, that's an improvement. I'm now getting the following issues though:

  1. When creating a node, I can add the top level paragraph. However, I cannot add any second level paragraphs, with this message: "You are not allowed to add any of the bundles.". I can, however, add second level nodes when I edit a node. This wasn't the case before patching.
  2. When translating a page the paragraphs fields are empty.

@RAFA3L can you confirm this?

codium’s picture

@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?

RAFA3L’s picture

Thanks @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:

Notice: Undefined property: ParagraphsItemEntity::$field_box in EntityTranslationDefaultHandler->initOriginalTranslation() (line 818 of /Applications/MAMP/htdocs/pruebas/sites/all/modules/entity_translation/includes/translation.handler.inc).

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.

codium’s picture

StatusFileSize
new76.7 KB

@RAFA3L

Do you mean saving node in this state?
Nested paragraph

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.

dan.ashdown’s picture

StatusFileSize
new5.75 KB

@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

codium’s picture

@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.

RAFA3L’s picture

Hello @codium, add the first level paragraph and don't add the second level nested, then save

dan.ashdown’s picture

@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.

dan.ashdown’s picture

Confirming @RAFA3L's issue with my feature:

Notice: Undefined property: ParagraphsItemEntity::$field_lvl2_paragraphs in ParagraphsItemEntity->save() (line 453 of sites/all/modules/contrib/paragraphs/ParagraphsItemEntity.inc).
Notice: Undefined property: ParagraphsItemEntity::$field_lvl2_paragraphs in EntityTranslationDefaultHandler->initOriginalTranslation() (line 818 of sites/all/modules/contrib/entity_translation/includes/translation.handler.inc).

This occurs when saving a new node with a lvl1 value but no lvl2

codium’s picture

StatusFileSize
new4.31 KB

@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.

dan.ashdown’s picture

Thanks @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.

RAFA3L’s picture

@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

dan.ashdown’s picture

Ah 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:

Notice: Undefined property: ParagraphsItemEntity::$field_layout_content in EntityTranslationDefaultHandler->initOriginalTranslation() (line 818 of sites/all/modules/contrib/entity_translation/includes/translation.handler.inc).

dan.ashdown’s picture

Just 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.

codium’s picture

@RAFA3L Cannot reproduce your bug - no errors/warnings/notices.

Maybe more detailed steps?

codium’s picture

Just 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.

This 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.

RAFA3L’s picture

StatusFileSize
new38.45 KB

@codium

Set the paragraph like this and save the new node

paragraph

codium’s picture

@RAFA3L doing exactly the same.

codium’s picture

@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?

RAFA3L’s picture

Thanks @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.

codium’s picture

Does anyone can test clearing entity translation table upon paragraph deletion?

RAFA3L’s picture

Doesn't clear here

RAFA3L’s picture

Hello @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:

Notice: Trying to get property of non-object in EntityTranslationParagraphsItemHandler->__construct() (line 51 of /sites/all/modules/paragraphs/includes/translation.handler.paragraphs_item.inc).

Why not just use this code?

function paragraphs_entity_delete($entity, $type) {
  if ($type == 'paragraphs_item') {
    foreach (array('entity_translation', 'entity_translation_revision') as $table) {
      $res = db_delete($table)
        ->condition('entity_type', $type)
        ->condition('entity_id', $entity->item_id)
        ->execute();
    }
  }
}
codium’s picture

@RAFA3L have you tested your code? If yes I'll use it instead or please update patch yourself

dan.ashdown’s picture

@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!

RAFA3L’s picture

@Dan.Ashdown do you get this error when delete a node with nested paragraphs?

Notice: Trying to get property of non-object in EntityTranslationParagraphsItemHandler->__construct() (line 51 of /sites/all/modules/paragraphs/includes/translation.handler.paragraphs_item.inc)

.

codium’s picture

@Dan.Ashdown 7.x-1.x-dev

dan.ashdown’s picture

StatusFileSize
new333.89 KB

Thanks @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.

Missing content

dan.ashdown’s picture

Actually, 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.

RAFA3L’s picture

@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

codium’s picture

@RAFA3L thanks for your effrot, @Dan.Ashdown for me rendering works with default ET settings also.

codium’s picture

StatusFileSize
new15.22 KB
new431.18 KB

As I mentioned before I was trying to implement tests for ET integration. During tests execution I got an Exception:

Exception: Cannot initialize entity translation path variables (invalid path scheme). in EntityTranslationDefaultHandler->initPathVariables() (line 1737 of /var/www/drupalvm/drupal/web/sites/all/modules/contrib/entity_translation/includes/translation.handler.inc).

Simpletests output

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.

RAFA3L’s picture

Hello @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

codium’s picture

@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.

codium’s picture

Status: Needs review » Reviewed & tested by the community
ciss’s picture

Status: Reviewed & tested by the community » Needs review

@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.

ciss’s picture

Status: Needs review » Needs work

Setting 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.

codium’s picture

@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.

codium’s picture

I've figured out how to bypass an exception during tests execution I've mentioned earlier. Tests are ready.

codium’s picture

WTF is happening with tests environment?

13:05:36 ERROR: Step ‘Publish JUnit test result report’ failed: No test report files were found. Configuration error?

codium’s picture

Just 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.

codium’s picture

Need support

codium’s picture

Status: Needs work » Needs review
codium’s picture

Status: Needs review » Needs work
codium’s picture

Reduce warnings output and remove entity translation configuration exception workaround.

codium’s picture

Fix all warnings during tests

Only local images are allowed.

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.

codium’s picture

Status: Needs work » Needs review
manojbisht_drupal’s picture

Hi @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.

stefanos.petrakis’s picture

Status: Needs review » Active

I 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.

codium’s picture

@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?

stefanos.petrakis’s picture

@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:

  • Why was the ideas and work leading up to #169 abandoned (e.g. known problems)?
  • Should there be an effort to merge the two patching approaches into one?
adsbisi’s picture

@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?

codium’s picture

@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.

codium’s picture

@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.

adsbisi’s picture

@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.

denix’s picture

Hi @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?

josecarlosss’s picture

Hello, 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?

codium’s picture

Hi @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

erichhaemmerle’s picture

Has 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

bohus ulrych’s picture

Hello 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.

rcodina’s picture

All 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:

git clone --branch 7.x-1.x https://git.drupal.org/project/paragraphs.git
cd paragraphs
wget https://www.drupal.org/files/issues/2018-09-01/paragraphs-entity_translation-2452675-270.patch
patch -p1 < paragraphs-entity_translation-2452675-270.patch

I can confirm that patch on #270 works like a charm. Thanks @codium!

denix’s picture

Status: Active » Needs review

Thanks @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

ciss’s picture

Thanks @codium for your patch! it seems that people are happy with it.

@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.

james.williams’s picture

Thanks 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->hostEntity can be NULL, 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!

james.williams’s picture

(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.)

Status: Needs review » Needs work

The last submitted patch, 288: paragraphs-entity_translation-2452675-288.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

james.williams’s picture

Status: Needs work » Needs review
StatusFileSize
new384 bytes
new69.25 KB

Variable module was needed as a test dependency.

Status: Needs review » Needs work

The last submitted patch, 291: paragraphs-entity_translation-2452675-291.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

james.williams’s picture

Status: Needs work » Needs review
StatusFileSize
new510 bytes
new69.37 KB

In 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.

Status: Needs review » Needs work

The last submitted patch, 293: paragraphs-entity_translation-2452675-293.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

james.williams’s picture

james.williams’s picture

StatusFileSize
new69.44 KB
new2.13 KB
new69.47 KB
new2.13 KB

Spotted 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!)

james.williams’s picture

Crikey, that was a botched upload somehow, very sorry! https://www.drupal.org/files/issues/2019-10-02/paragraphs-entity_transla... is the correct patch.

james.williams’s picture

StatusFileSize
new1.34 KB
new69.48 KB

Found 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 adding clone?) from getTranslations(). 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!)

james.williams’s picture

StatusFileSize
new1.69 KB
new69.49 KB

Urgh, I found an issue immediately, so please ignore the files in my last comment, use these instead. Sorry for all the noise.

nono95230’s picture

StatusFileSize
new28.74 KB

I'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.

james.williams’s picture

@Nono95230 why did you go from patch 254, leaving out the work that's been done on numerous patches since then?

guillaumeduveau’s picture

@james.williams because he's been working on it for 1 year

anybody’s picture

@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.

james.williams’s picture

Status: Needs work » Needs review

The 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.

james.williams’s picture

Ah, the patch from #299 needs re-rolling.

anybody’s picture

Thank you very very much. I really appreciate your work, @james.williams!

james.williams’s picture

Issue tags: -Needs tests
StatusFileSize
new62.4 KB

Here'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:

  • One was added way back in comment 38, in 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.
  • The other two were added in comment 170, The first, in 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.
  • The other, in 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.

Status: Needs review » Needs work

The last submitted patch, 307: paragraphs-entity_translation-2452675-307.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

james.williams’s picture

So 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.

james.williams’s picture

StatusFileSize
new12.14 KB
new61.68 KB

This should resolve most of the new coding standards messages, hopefully.

gravisrs’s picture

#310 usually works but in such case:

  1. Enable entity translation support for both - nodes and paragraphs (ET config page).
  2. Create node type (with entity translation enabled).
  3. Create paragraph bundle, consisting of some fields (doesn't matter if those fields have translations enabled or not).
  4. Add paragraph field to the node type with translations disabled. Select previously created bundle to be allowed here.
  5. Create a node with that paragraph.
  6. Enable translation for this paragraph field (selecting copy translations or not, doesn't matter).

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.

anybody’s picture

Status: Needs work » Needs review

We'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!

rcodina’s picture

@Anybody I just cloned the repository and patch on #310 applied cleanly. So no reroll needed. Of course, the patch works well. Good job!

proweb.ua’s picture

paragraphs 7.x-1.0-rc5+37-dev + #310

patching file ParagraphsItemEntity.inc
patching file README.txt
patching file includes/translation.handler.paragraphs_item.inc
patching file paragraphs.field_widget.inc
patching file paragraphs.info
Hunk #1 FAILED at 8.
1 out of 1 hunk FAILED -- saving rejects to file paragraphs.info.rej
patching file paragraphs.module
patching file tests/content_page/content_page.features.field_base.inc
patching file tests/content_page/content_page.features.field_instance.inc
patching file tests/content_page/content_page.features.inc
patching file tests/content_page/content_page.features.language.inc
patching file tests/content_page/content_page.features.user_permission.inc
patching file tests/content_page/content_page.info
patching file tests/content_page/content_page.module
patching file tests/content_page/content_page.strongarm.inc
patching file tests/paragraphs_entity_translation.test

gravisrs’s picture

StatusFileSize
new61.68 KB

Looking 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

Igumnov_aleksey made their first commit to this issue’s fork.

Igumnov_aleksey’s picture

StatusFileSize
new61.71 KB

When 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:

TypeError:method_exists(): Argument #1 (object_or_class) must be of type object|string, null given in method_exists() (.../paragraphs/includes/handler.paragraphs_item.inc)

I propose to add next changes to the patch:

if ($this->hostEntity !== NULL && $host_entity_type === 'paragraphs_item') {
Igumnov_aleksey’s picture

StatusFileSize
new61.74 KB

I have updated my patch. I changed the condition to most properly.

if (is_object($this->hostEntity) && $host_entity_type == 'paragraphs_item') {
aquaphenix’s picture

Re-rolling changes in #315 and #318

Status: Needs review » Needs work

The last submitted patch, 319: paragraphs-entity_translation-2452675-319.patch, failed testing. View results

bluegeek9’s picture

Status: Needs work » Closed (outdated)
//www.flaticon.com/free-icons/thank-you Thank you for your contribution!

Unfortunately, Drupal 7 is End of Life and no longer supported. We strongly encourage you to upgrade to a supported version of Drupal.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.