Field collection should support multilingual.
Specification of translatable FC
Consider the following case:
- A translatable node 'About' has a long text field 'Body' and a field collection field 'Summary'.
- The 'Summary' FC has two fields: 'Image' and 'Short text'
The About content type:
- The About node type is translatable; Example: Title, Body, Author are marked translatable.
- The Summary field (inside the About node type) is _not_ marked translatable
The Summary field collection configuration:
- The 'Summary' FC is translatable.
- The 'Image' field (inside FC) is marked translatable; Alt and Title are translatable, Field is not (not relevant for the case).
- The 'Short text' field (inside FC) is marked translatable.
Comments
Comment #2
penyaskitoWe have several choices for translatability, which I'm not sure which one should we prefer.
1. Translate the field collection items as its own entity.
2. Translate the child fields themselves and maintain the same reference to the field collection item entity in all translations.
Right now field collection items are marked as not translatable, which may imply that we want to translate the child fields themselves, not the entire collection (option 2). This makes harder the integration with content_translation, but probably it has been discussed before why choose that one.
Any hints?
Comment #3
jmuzz CreditAttribution: jmuzz commentedI believe #2 is the more common use case, and it is the only one that I personally have encountered. Consider the example mentioned in the other ticket about this... "If I have a field collection with an image and a text, I may want to only translate the text field." It wouldn't be possible to implement that while creating an independent group of field collection items for each of its host's translations. #2618156: Translatability settings on the content translation page
There may be some value in adding the option for #1 as well, but it would be more difficult to implement and use the module if they were both supported, especially when considering nested field collections that may not use the same option as their parent.
#1 is (or will be) supported by using content translation, so it may not be necessary to support it in entity translation too.
Comment #4
penyaskitoI think @tim.plunkett is exploring new ways of doing 1), which could have multiple benefits (not only translatability), by wrapping entity_reference.
Comment #5
dramblys CreditAttribution: dramblys commentedQuick qeustion: were there any work done on field collection translatability problem to pick up from or is it in the process of consideration and planning?
Reason to ask, have a project with field collections (in some cases 2 level deep) and tmgmt. It's important for the client to have all content translations to be exportable/importable.
Maybe someone has any solutions for this?
Comment #6
jmuzz CreditAttribution: jmuzz commentedThere has been no specific work done to add translation support to 8.x-1.x.
8.x-2.x is essentially a rewrite, so a separate issue can be made for it.
Unless there are any objections we can pursue option #2 here.
Comment #7
jmuzz CreditAttribution: jmuzz commentedCome to think of it, the two options shouldn't be too hard to combine from a UX perspective, even if that doesn't make the implementation any easier. The thing to enforce would be if a field collection field is translatable then none of the fields inside it (including nested field collections and their subfields, no matter how deep) could be translatable.
Comment #8
jmuzz CreditAttribution: jmuzz commentedThe way I see it, the path to implementing translation for field collections looks like:
Comment #9
jmuzz CreditAttribution: jmuzz commentedThe image module provides translatability options for its built in subfields such as title and alt. These options appear on the general translatability settings page and the settings for the field itself. As a UI it seems to provide a reasonable way to set the options, though I don't think we'd want to copy the behaviour all the way through because even when the files themselves are set as not translatable the image fields are still allowed to have completely separate sets of images for each translation of a piece of content. If we are to make the inner fields in a field collection translatable we'd want to enforce a 1 to 1 pairing between field collection items in each translation.
Comment #10
dramblys CreditAttribution: dramblys commentedI've done some work towards fc multi-language.
Run /update.php for existing content (please make sure you have DB backup).
As far as I've tested it's working on fresh install (deletion needs to be tested better).
Please review and feel free to make any kind of remarks.
Comment #11
jmuzz CreditAttribution: jmuzz commentedThanks @dramblys. It looks like a lot of functionality is here.
I'm interested in looking more at what this will do. A few general comments:
\Drupal::entityDefinitionUpdateManager()
should be used instead.For more details see:
Can you explain a bit about how your solution handles translating the field collection fields in the host entity vs translating the inner fields as per #2, or where there this gets us with respect to the plan in #8?
Comment #12
dramblys CreditAttribution: dramblys commentedPlease note #10 patch is good for fresh site installs only, working on the implementation for sites with existing fc content. Also I've noticed a floss: e.g. when deleting node translation it deletes the field collection, not the translation of it.
@jmuzz Thank you for remarks, working on it ;)
What this patch does:
Regarding #2
1. Translate the field collection items as its own entity
Regarding #8
1. No
2. Yes
3. Yes
4. Yes
5. Yes
6. Manual as it is for all other translatable entities
7. No
8. No check, though nested field collection item are translatable as well
9. Not sure what you meant by that
10. Again, not sure
11. Nothing have been documented till final tested release
And I need to do more testing - working progress ;)
Comment #13
dramblys CreditAttribution: dramblys commentedSome more work done. Everyone feel free to review, test, make remarks.
Notes
field_collection-multilanguage-2618016-2.1-8.1.x.patch - this one is for changes in the module itself for translatability on new fresh installations.
field_collection-multilanguage-2618016-2.2-8.1.x.patch - this is basically .install file for updating projects with content in field collections (FC).
Instructions
For new installations: apply field_collection-multilanguage-2618016-2.1-8.1.x.patch.
For projects with content in FC:
1. Backup your DB.
2. Make sure you can rebuild cache and run update without being logged in or using admin panel.
3. Apply both patches.
4. Rebuild cache
5. Run /update.php
Comment #14
dramblys CreditAttribution: dramblys commentedAfter some testing, working version:
Comment #15
dvanbrenk CreditAttribution: dvanbrenk commentedHi dramblys,
Unfortunately your patches (3.2) doesn't work for the site of my client. I'm getting the following error: "Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'langcode' in field list is ambiguous:" etc etc. See everything: http://pastebin.com/XftHEumh
Can you please help me? Thanks in advance.
Diederick
EDIT: ok, it's fixed. Don't used your patches. Instead I'm deleting the field collection after I'm making a translation of a page.
Comment #16
Tom.W CreditAttribution: Tom.W commentedHi Dramblys,
I'm seeing issues with your patch as well, once I enable translation for field collection content it seems to permanently break the field collection content and the node cant be saved again due to the following error
Drupal\Core\Entity\EntityStorageException : SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'field_name' cannot be null: UPDATE {field_collection_item} SET item_id=:db_update_placeholder_0, revision_id=:db_update_placeholder_1, field_name=:db_update_placeholder_2, uuid=:db_update_placeholder_3, langcode=:db_update_placeholder_4 WHERE (item_id = :db_condition_placeholder_0); Array ( [:db_update_placeholder_0] => 250 [:db_update_placeholder_1] => 250 [:db_update_placeholder_2] => [:db_update_placeholder_3] => 8e80c44f-d264-4dee-9596-fd00a4b3c527 [:db_update_placeholder_4] => en [:db_condition_placeholder_0] => 250 ) dans Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (ligne 770 de /var/www/vagrant/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
I've tried this with a fresh install of fc with your patch, creating new field collections etc... and i always end up with the same issue. Have you experienced this at all?
Comment #17
Tom.W CreditAttribution: Tom.W commentedHi Dramblys,
Ignore the above comment, it was due to interaction with another module. One real issue i did note however is that the field collection translation does not 'clear up' its old values when you delete it. They do get deleted successfully when the entire field collection is removed, but the current behavior means that if you delete and create a new translation you will get all the old field collection values added, which appears a little odd from a content management point of view.
Comment #18
dramblys CreditAttribution: dramblys commented@dvanbrenk will try to have a look today/tomo
@Tom.W I'm glad that someone is using mu implementation ;) Regarding the issue of translation delete functionality - you are absolutly right, I've spent some time to fix it, but had no more time for it so far.
If there would be more interest in the further development of this implementation I could spend more time to fix it.
Comment #19
sic CreditAttribution: sic commentedThere indeed is.
Comment #20
sic CreditAttribution: sic commentedThe update doesnt work for existing field collections.
Comment #21
heddnI know this might seem like a nit. But the code style in the patch for upgrading is pretty far from normal Drupal projects. Any chance we can get something that more closely aligns to ? It make reviewing extremely complicated.
Some comments below and here's a link to the coding standards: https://www.drupal.org/coding-standards
Why double underscores?
Where is the function docs?
This type of doc block normally goes on the function. Inline comments are formatted differently.
This will only work on SQL backed installs of Drupal. Why can't we use the query api provided in D8?
Comment #22
heddnAlso, the docs in https://www.drupal.org/node/2535476 are probably worth a read.
Comment #23
heddnGoing to take a stab at some of this feedback today.
Comment #24
jmuzz CreditAttribution: jmuzz commentedDevelopment is moving to 8.x-3.x.
About the deletion issue: If the field collection fields themselves are translatable instead of the inner fields they will need to be completely separate datasets for each translation. This means cloning the field collection objects when a translation of their host gets made. If you want to have each translation pointing to the same field collection items and with each item having multiple translations so the inner fields can be translated that does mean that deleting a field collection item in one translation will delete it in all of them.
Comment #25
heddnOK, very little testing, but here's some changes to the hook update. My testing to this point shows that nothing blows up on update. Interdiff is against only the base functionality in #14 as there is nothing in common on the hook update.
Comment #27
heddnComment #29
sleitner CreditAttribution: sleitner commentedIn a more than two language setup, with a node already translated in two languages(e.g. english and french):
If you change the source language during node translation (to e.g. german) from default source language (e.g. english) to another language (e.g. french), the field content of the field_collection fields stay in the default language(english). The field content should be loaded from the selected language( french).
Non field_collection fields show the right field content in the selected language(french).
Comment #30
sleitner CreditAttribution: sleitner commented1. @heddn I added source language support(#29) to the field_collection-multilingual_support_in-2618016-27.patch patch
2. in case you delete a node translation(#12) all field_collections of all translations of this node are deleted. Only delete the current translation:
Comment #31
paulguy CreditAttribution: paulguy commentedI'm trying to apply those patches but can't get it works.
First of all which version are they made for ?
It seems that's for 8.x-1x-dev but update script crash with this exception :
LogicException: The Field Collection Item entity type cannot be translatable as it does not define a translatable "langcode" field.
As comment #24 says development moved to 8.x-3.x I also tried on this version. Update goes well but I couln'd create or even see nodes with FCs in it.
Does someone manage to make it works ?
Comment #32
FooZee CreditAttribution: FooZee at Media.Monks commented@paulguy I wasn't able to apply them either, nor find which point in git history were those patches written against, so I ended up merging them manually with the latest 8.x-3.x-dev but it still needs some extra work to actually work. I'll post a patch as soon as I have it working.
Comment #33
FooZee CreditAttribution: FooZee at Media.Monks commentedOkay, a followup on my previous comment (just for political correctness ;) ).... it looks like those patches were written against 8.x-1.0-alpha1 which is no longer in use however.
Comment #34
paulguy CreditAttribution: paulguy commentedThanks for your answer. In a way I'm glad to know that I didn't miss something when I tried...
We ended to create a new node for each language when collection were used. But that's a quick & dirty solution so let me know if you create a new patch and i'll be happy to test it.
Comment #35
Sutharsan CreditAttribution: Sutharsan commentedHave a look at Inline Entity Form, and in particular #2494959: Add translation integration. Translation is (partially) working there, It looks like good example code.
Comment #36
FooZee CreditAttribution: FooZee at Media.Monks commentedAttached is the re-rolled patch against latest 3.x-dev. it's not exactly working, but that's what is initially ported. I'm still trying to get working version soon.
Comment #37
FooZee CreditAttribution: FooZee at Media.Monks commentedNow translations work, but I'm not a big fan of using path for how deleting translations is originally written, I'm looking into other possible ways, because what if we are deleting a translation programmatically, or as part of a batch job ...
Comment #38
FooZee CreditAttribution: FooZee as a volunteer commentedOkay, after a little bit more testing, I found the following piece of code in
ContentEntityStorageBase::invokeFieldMethods
(which basically is responsible for invoking\Drupal\field_collection\Plugin\Field\FieldType\FieldCollection::delete
what that practically means is: fieldType
delete()
methods are never called for fields that are not marked as translatable ... that makes a lot of sense, but not for fields that reference entities that are editable on the parent entity form (e.g. FieldCollection, Paragraphs, IEF ... ) actually I could reproduce the same behavior with paragraphs as well, and I'm filing a separate bug there, but it's certainly worth thinking whether we should implement another method to hook into the deletion of parent items translation and delete corresponding FC translations or is that just kind of an overkill? thoughts are really welcome here.Comment #39
FooZee CreditAttribution: FooZee as a volunteer commentedComment #40
murillosampaio CreditAttribution: murillosampaio commentedFooZee this patch works with existing nodes?
Comment #41
PierreRicci CreditAttribution: PierreRicci commentedHi all,
Is the patch field_collection-multilingual_support_in-2618016-37.patch work and is ti work with production site with content in fc ?
Is it the only file to appply ?
Reagards
Comment #43
CreativeClaire CreditAttribution: CreativeClaire commentedHi FooZee,
I would love to have Translation working with Field Collections in Drupal 8. So we think about the propper "delete()" method, and then we can maybe commit that into the actual "8.x-3.x-dev" branch of the module? That would be great. Are you still working on the issue and want some opinions about your question? If yes, I would really like to help out!
Best regards,
CreativeClaire
Comment #44
Sutharsan CreditAttribution: Sutharsan commentedUpdated the issue summary with more details of the required situation which we call "translatable".
Comment #45
sleitner CreditAttribution: sleitner commentedDelete function is updated without getPathInfo(). Patch against 8.x-3.x-dev(2016-Nov-21)
Comment #46
scaldinglake CreditAttribution: scaldinglake commentedSorry, just jumping in after going through the comments/patches
Somehow, the schema definition for field_collection_item_field_data got lost around #37, which will cause the following error when trying to translate items.
Hopefully I can provide a patch, but I'm currently rushing towards a deadline
Comment #47
scaldinglake CreditAttribution: scaldinglake commentedWell, that was short lived, I added the schema back in from the 30 re-roll patch, was able to add translatability to my field collections, but as soon as I went to the front end, I got the following message
Unfortunately I don't have any time to keep at this currently, but I hope it helps figure out some of the issues, sorry!
Comment #48
CreativeClaire CreditAttribution: CreativeClaire commented@sleitner: The 'delete()' method doesn't seem to work properly. I'll explain (1) What I did and (2) What the error is.
(1) What I did:
(2) What's the error:
When I delete the secondary translation (English in my case), that works well. But when I try to delete the primary translation (German in my case), that happens:
That's not good, right? I used the "field_collection" module, version "8.x-3.x-dev" (2016-Nov-21) and the patch "field_collection-multilingual_support_in-2618016-45.patch". I'll try out patch "field_collection-multilingual_support_in-2618016-37.patch" soon.
Or did I do something wrong? Otherwise I hope my testing helps.
Comment #49
Sutharsan CreditAttribution: Sutharsan commentedI had (the same) problem deleting a translated node with field collections. The attached patch fixed it for me.
Comment #51
paulguy CreditAttribution: paulguy commentedFirst of all thanks for all the work done !
I can't get the update.php script working with the last patch.
field_collection_update_8003 is detected but anytime I try I get this error :
With no other logs or error :( Am I the only one ? Maybe its not a FC issue but I can't figure out why...
Comment #52
paulguy CreditAttribution: paulguy commented@myself Ok with php error logs I saw that I forget to add the 2 use lines on the top of field_collection.install file ...
Patching a module manually is definetively not the good way to go !
More testing now
Comment #53
paulguy CreditAttribution: paulguy commentedEditing a content with FC lead to an error "entity (X) doesn't exist", I had to recreate every FC.
Thats not a big deal but adding or editing a content with FC always lead to this error now :
Also I had to apply an update hook from patch #25 to get field_collection_item_field_data table.
My production site use FC 8.x-1.0 and i'm trying to update to 8.x-3.x with translations. Do I have to apply other patches thatn those of this page ?
Comment #54
heddnNot to be a damper here, but for those coming to this issue, they might want to consider there is an alternative to field collections in D8. And paragraphs already supports multi-lingual.
#2784931: Proposal: Deprecate Field Collections for Drupal 8, focus on Entity Reference Revisions & Paragraphs
#2831131: [META] Outperform field collections
Comment #55
Sutharsan CreditAttribution: Sutharsan commented@paulguy, the patch does _not_ work with existing field collections. An upgrade path is not (yet) available.
Comment #56
CreativeClaire CreditAttribution: CreativeClaire commented@heddn: Thanks for the hint. Just tried it with the "paragraphs" module, translation works pretty well.
Comment #57
artreaktor CreditAttribution: artreaktor as a volunteer and commentedHere is the update script for existing 1.x field collections. It is working well for default language content, but I'm not completely sure about other languages. For now I have only default language content and few translated items. The translated items aren't looking good (missing or extra items), so I'll delete and re-translate them.
Apply it after #49.
Comment #58
artreaktor CreditAttribution: artreaktor as a volunteer and commentedThe previous patch doesn't fix some items with empty host_type value, so here is the additional patch. Apply after #57. Run updates afterwards.
Comment #59
lathanlast amendments by @artreaktor fail for me.
Comment #60
artreaktor CreditAttribution: artreaktor as a volunteer and commented@lathan, there should be "langcode" field in "field_collection_item" table according to 8.x-3.x version of FieldCollectionItem annotation
Comment #61
paupale CreditAttribution: paupale commented@artreaktor I can confirm that I get the same error as @lathan.
Comment #62
dawehnerI tried out the patch + the patches posted by @artreaktor in #57, #58. I ran into a couple of issues, like #59, which, even if its fixed, causes more issues, see my review below.
This is missing the data / revision data table.
This is the wrong entity type :)
Comment #63
rajivpatel16 CreditAttribution: rajivpatel16 as a volunteer and commentedHello Team,
I am using drupal8 I am trying to translate filed collection item in views. but its is not translating. I use the same option. which i used for other content types field. please help me. i am stuck
Comment #64
DhirendraGrazitti CreditAttribution: DhirendraGrazitti commentedHello All,
I am working on a website with version Drupal 8.5.3 and using core multilingual module for translation when I try to translate that there was the problem in field collection areas, It translates both nodes same times. Normally new translated node/page is only linked and does not share same content if I change that, But in this case, when I change in English same content I am seeing in German page. If I change in German same content is seeing in the English page.
E.g I have a content type testimonials whose field is Title, Body and Field collection Meta Content whose fields are
Normal Content, Left Content, and Right Content. Now in this Title and Body is translating properly but Meta content field collection when I update content in one node the same content is showing in other language nodes.
Any help appreciated? How should we resolve the Issue?
Comment #65
Omar Alahmed#49 works for a fresh installation of FC.
@Sutharsan thanks.
Comment #66
ram4nd CreditAttribution: ram4nd as a volunteer commentedComment #67
MartinMa CreditAttribution: MartinMa as a volunteer commentedI too miss multilangual support. If this missing issue wont be fixed, is there an alternative modul instead of field group? Just only need it to group on the page tags and further information links/downloads etc.
Comment #68
MartinMa CreditAttribution: MartinMa as a volunteer commentedIf the maintainer doesnt want to fix the missing feature translation, why should the community not to give it a further chance?
In D7 there was also work on a patch:
https://drupal.org/node/1344672
https://drupal.org/node/1316162
Strreamlined multilingual is one of the main progress of D8 so I wonder if there would be no solution for field collection.