First my "rant":
this is very important module and to be honest; not sure how people can consider starting to work with D7 (for sites as complex as they could have done in D6) until there is a working version of this module available.. and there are a lot of issues with this module still!!
here endeth my rant..
Cloning
Perhaps this is by design but seems likely to be the far less obvious use case:
if you clone an node that has collection fields; the collection is not cloned. that is to say a new field is not created; the cloned node simply points to the old collection. so any changes to this field in either the original node or the cloned node.. will appear in both nodes.
pretty sure that wouldn't be expected behavior.
Comment | File | Size | Author |
---|---|---|---|
#28 | field_collection-1304214-28.patch | 2.12 KB | vgoodvin |
#26 | field_collection-1304214-25.patch | 2.26 KB | vgoodvin |
#25 | field_collection-1304214-25.patch | 2.12 KB | vgoodvin |
#20 | field_collection-1304214-20.patch | 2.32 KB | fuerst |
#9 | Issue 1304214.diff | 2.66 KB | gabrielu |
Comments
Comment #1
liquidcms CreditAttribution: liquidcms commentedthis should be under the node_clone project; and it is a duplicate of an issue there #1233256: Integrate node_clone with field_collection module
Comment #2
mrconnerton CreditAttribution: mrconnerton commented#1233256: Integrate node_clone with field_collection module is producing some great code, but ultimately field collection should support node_clone module by implementing hook_clone_node_alter in the same fashion the webform module does.
I need this right now so I will see about posting a patch here shortly.
Comment #3
mrconnerton CreditAttribution: mrconnerton commentedThis is a patch that pulls together the other work done to make this happen. It implements hook_clone_node_alter and creates a helper function for cloning field collections.
Comment #4
sarasioux CreditAttribution: sarasioux commentedWorked great for me! Will be pushing this patch to production on Monday after preliminary tests this weekend, will let you know if we run into anything unexpected, but so far it's working perfectly!
Comment #5
tim.plunkettJust some coding style and optimization, the code looks good overall.
Instead, I think this could be just
array_keys(field_info_instances('field_collection_item', $fc_field));
Missing space after foreach
I think that
$field_name
should be used here instead of$fc_field
.I'd like to avoid using fc as an abbreviation, I think it can be $old_item and $new_item
These three lines could probably be moved outside the foreach, and cloned each time through.
Missing space after the comma.
Instead, I think this could be just
array_keys(field_info_instances('field_collection_item', $fc_field));
Comment #6
mrconnerton CreditAttribution: mrconnerton commentedGreat, thanks Tim. I will roll a new patch tomorrow.
Comment #7
muschpusch CreditAttribution: muschpusch commentedThe patch doesn't work for 100% when they are required fields in the field collection. The node is cloned but there is an error that field X is required. Thanks for the patch anyway since the most important part "cloning" is working fine!!!
Comment #8
gabrielu CreditAttribution: gabrielu commentedI tried your patch, but didn't worked in my case. Somehow the form gets no fields after the line field_collection.php:1067
My scenario:
We have a field collection with 3 values filled in, we clone the node (it works), and we want to leave only 2 values from the 3, so we delete one of them (nothing happens + "Uncaught Syntax error, unrecognized expression: # " JS error
What I tracked down, the form has no more fields after you run the "drupal_process_form".
I am not sure if it's field_collection or node_clone that I should work on...
Thanks,
Gabriel
Comment #9
gabrielu CreditAttribution: gabrielu commentedLooks like Field collection is not loading the necessary node.inc files. See attached patch.
BTW: This also includes the above patch. You can only consider my changes to the function field_collection_remove_js()
I don't know if there is any better way of doing this.
Gabriel
Comment #11
guldi CreditAttribution: guldi commented#3 worked for my purpose.
how is this going further? I suggest a commit asap!
Comment #12
sven.lauer CreditAttribution: sven.lauer commentedI just tinkered with some code based on the suggestions in #1233256: Integrate node_clone with field_collection module---and I found that the saving of the fc items is problematic (in fact, the fc-items get not saved, but the host entity still gets populated with IDs---presumably the IDs that would have resulted if db transaction were not rolled back) if the new host entity is not yet saved---and actually, the way setHostEntity() works (now) makes saving the fc-item unnecessary: Removing the call to save() makes everything work.
Posting here since the patches are builton the code from #1233256: Integrate node_clone with field_collection module and include the offending call to the EntityMetadataWrapper->save().
(That is to say, if you want to make the patch work for unsaved host entities, remove that call to save().)
Comment #13
liquidcms CreditAttribution: liquidcms commenteddue to the odd nature of this issue in that it looks like the clone has actually worked, until you start making changes.. i have lived blissfully for months thinking this had been fixed.. got a bit nervous when i saw the issue was still open.
just tried the patch in #3 on our crazy node type which is about 700 fields (many of which are required) with dozens of collections nested 4 levels deep and other than a pile of errors (which are related to numerous computed fields in this mess and not related to this issue)... i can report that the cloning seems to have worked successfully.. :)
took much longer to do the clone now, obviously, since it wasn't really doing all that much before and now it is creating clones of numerous collection entities but very excited to see this work.
more testing to do tomorrow; but i'd vote for getting this committed. and i think i owe Matt (mrconnerton) a few (cases of) beer.
Comment #14
mrconnerton CreditAttribution: mrconnerton commented@liquidcms I accept your beers :-). Will meet you at the next camp/con
@sven.lauer I am having a bit of trouble interpreting what you are saying. I think its either "OMG THIS ISN'T ACTUALLY WORKING!!!" or "It works but not for unsaved host entities"?
As for getting it commited, I think a new patch needs to be rolled with the review from #5 that I never got around to doing
Comment #15
Ludo.RAre you still planning to commit this patch (it it works)?
Thanks!
Comment #16
Ludo.RAfter trying the #3 patch (against version 7.x-1.0-beta4), I think there is still an annoying issue.
When I clone a node, it is copied twice, so I get :
The third one has its own field collection values (its own records in the database), but should not have been created.
EDIT : It seems there is a node that is created right after clicking the clone link, although I've set the clone module method to "prepopulate". And when saving the node edit form, a new node is created again.
Comment #17
Ludo.RI think the field_collection_clone_items() function from #3 patch should not be saving anything if the node_clone module method is set to "prepopulate".
It should only prepopulate the passed entity.
But I can't figure out how to fix it since I'm not comfortable enough with Entity API/Field collection.
Maybe putting a condition around the entity save function should be enough :
Then the $context variable should be passed from
field_collection_clone_node_alter()
function tofield_collection_clone_items()
function.Comment #18
alanburke CreditAttribution: alanburke commented#9: Issue 1304214.diff queued for re-testing.
Comment #19
alanburke CreditAttribution: alanburke commentedPatch works fine, but with the same issue as in 16 [ 2 new nodes are created]
Switching to the 'Save as a new node then edit ' method avoided the problem.
Comment #20
fuerst CreditAttribution: fuerst commentedAdjusted #3 for the current 7.x-1.x, also applies to 7.x-1.0-beta4. I put some coding style changes in but did not optimize as #4 advised.
Comment #21
fuerst CreditAttribution: fuerst commentedFYI: To get information about nodes which are sharing Field Collections you may use the following SQL-Queries:
First get all Field Collections:
Second use the resulting table_name's and value_column's to check for Entity IDs which are sharing Field Collections like this for every table_name:
Every resulting line will contain Entity IDs which share a Field Collection.
You now may remove a shared Field Collections from a node (or entity) by deleting the corresponding record from <table_name>.
Comment #22
thoughtcat CreditAttribution: thoughtcat commentedI'm not sure if this is the same problem, but when I clone a node with a field collection, it clones fine, but when I try to add a new field collection ("add another item" - my content type allows an unlimited number of field collections) I get:
If I save the node without adding a new field collection I can then edit it and add the new field collection with no problem. This workaround though won't help my users, who most of the time would be cloning the node precisely in order to add a new field collection.
If this isn't what the original issue is about let me know and I'll create a new issue.
Comment #23
ghalenir CreditAttribution: ghalenir commentedThis patch worked for me too.
Comment #24
fuerst CreditAttribution: fuerst commentedSo we can set the issue to RTBC.
Comment #25
vgoodvin CreditAttribution: vgoodvin commentedThis patch worked for me when I used "Save as a new node then edit" option from Node clone module settings page. When I used "Pre-populate the node form fields", then new node appeared just after clicking the "Clone" link.
I updated this patch to work with both "Pre-populate the node form fields" and "Save as a new node then edit"
Comment #26
vgoodvin CreditAttribution: vgoodvin commentedIf you have problems with applying this patch, then you can try using patch below.
Comment #27
jason.fisher CreditAttribution: jason.fisher commented#26 has sites/all/modules hardcoded instead of current path
Comment #28
vgoodvin CreditAttribution: vgoodvin commentedUpdated patch
Comment #29
Anonymous (not verified) CreditAttribution: Anonymous commentedhi there,
i'm in urrrgent need of a solution for this cloning thing of field collections (tomorrow, my head will role ), and i only found out today that there is an issue (stupid me, didn't test beforehand).
can anyone tell me which of those patches might work on which version at the moment?
i tried around and only wrecked the site so far.
thanx
bernd
Comment #30
RoSk0Patch from #28 works for me.
Comment #31
liquidcms CreditAttribution: liquidcms commentedthis is marked as being for -dev but this was originally from a -dev prior to any of the beta releases
can anyone confirm what rev this patch is for now? i don't think it works with beta5 (or latest -dev)
to be clear: the patch applies correctly; but cloning doesn't even copy over the values from original.
my guess would be the recent addition of collection revisions has broken the ability for this patch to do what it was trying to do (the patch did work for earlier versions of FC).
Comment #32
VladSavitsky CreditAttribution: VladSavitsky commentedWe (I and RoSk0) are using this patch against 7.x-1.0-beta4 and it works fine.
Comment #33
liquidcms CreditAttribution: liquidcms commentedbeta4 is pretty old; is it really beta4 or a -dev between beta4 and beta5?
i was using -dev from Oct 2012 which technically is beta4+ and yes, your patch works. it doesn't work with beta5 - i am looking in to it.
Comment #34
liquidcms CreditAttribution: liquidcms commentedand by doesn't work i mean the clone loads no data from items which are in field collections - i.e. the edit form you get after cloning has no data. which is why my guess is that collection revisions has broken this.
Comment #35
rongok CreditAttribution: rongok commentedThe patch from #28 works with beta5.
Comment #36
slolawk CreditAttribution: slolawk commentedThe patch from #28 does not work with beta5.
Comment #37
btopro CreditAttribution: btopro commented#28 looks sound, for those looking for a more direct solution I did this recently so I don't have to patch for a 1-off. If you swap out the module name, form_id and field_games field name with your associated values this will work as well. Patch is much more generic and preferred solution, just wanted to post to help other devs in a pinch.
Comment #38
chx CreditAttribution: chx commentedis enough. Thanks for the simple code!
Comment #39
jonh CreditAttribution: jonh commentedHow can I identify nodes that have already been affected by this?
Comment #40
dppeak CreditAttribution: dppeak commentedI've successfully applied the patch from #28 against beta5 and everything is working great for me.
Comment #41
spazfoxI've applied the patch from #28 to beta5 and it is working great for me, too.
Comment #42
spazfoxCorrection: The patch from #28 is not working for me using beta5. I'm trying to use it for a node that has a field collection with an unlimited number of values allowed (and 12 of them in the original node are filled with data in this case), so the problem may be specific to my use case.
The problem I'm experiencing is this: when I attempt the clone, the values for the first instance of the field collection are cloned correctly, but each of the subsequent instances simply repeats the values from the *last* instance of the field collection from the original node. It appears there may be a missing loop in the patch to cover field collections with unlimited values, though I'm not familiar enough with D7 fields or this module to figure it out at this point. If I do, I'll post a fix.
Comment #43
Danny EnglanderI tested the patch from #28 (against the latest dev) and it fixed the issue for me as well. Thank you.
Comment #44
Itangalo CreditAttribution: Itangalo commentedComment #45
asb CreditAttribution: asb commentedThe patch from #28 still applies with an offset:
However, it does not fix the issue. I have the same problem as described in #42.
If I delete the mutilated data, things get worse. There is no editable field collection anymore, and I get the error:
Notice: Trying to get property of non-object in field_collection_field_get_entity() (line 1644 of /var/www/d7/sites/all/modules/field_collection/field_collection.module)
Since there is no workaround and this bug mutilates data, changing category to "bug report" and priority to "major".
Comment #46
jmuzz CreditAttribution: jmuzz commentedSince the patch for #1316162: Support content translation and host entity cloning is applied field collections should support their host being cloned now. I think this can be closed as a duplicate. Can anybody confirm with the latest dev version?
Comment #47
asb CreditAttribution: asb commentedI'm using field_collection 7.x-1.x-dev from 2014-Jul-24. In this version, the issue still exists as described above: Cloned nodes with an attached field collection inherit the data from the last edit, back to the initial node that was cloned. It is not possible to enter data on cloned nodes without affecting the prior generations of clones. If you have 9 cloned nodes and edit one of them, you alter a total of ten nodes (clones plus original).