Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
This is forked from #1186826: Delete orphaned field_collection_item entities when they are (programatically) removed from the host entity.
Some have found the reverse situation can cause issues - when programmatically deleting the field_collection_item entity that the fields that referenced did not have their values cleared.
Comments
Comment #1
jamsilver CreditAttribution: jamsilver commentedFrom http://drupal.org/node/1186826#comment-5111484:
From http://drupal.org/node/1186826#comment-5196922
Comment #2
Daniel Wentsch CreditAttribution: Daniel Wentsch commentedI've got the same problem and no solution, but I can confirm Lerain's method of adding those values manually to the database worked for me, too.
It might be of interest that I'm using i18n and the problem occured after adding a node translation.
Comment #3
Daniel Wentsch CreditAttribution: Daniel Wentsch commentedGood news :)
I managed to track the bug, at least in my case.
It is indeed related to i18n. Whenever a translated node was deleted the original node got corrupted.
Luckily there's already a available patch for this:
#1315432: Deleting a translated node with a collection also deletes the collection entity ..
Worked out for me.
Comment #4
melissavdh CreditAttribution: melissavdh commentedI am also getting this problem, and I'm not using any node translations so I think it's for a different reason to klickreflex. I just have some very simple code; a node is programmatically created and the user has the option to edit the node and add/edit/delete any field collections through an interface I have written (not the standard drupal node UI). When the user edits this node and deletes a field collection, that field collection item deletes successfully but the reference from the node to the field collection still remains. I then get the "EntityMalformedException" error mentioned above when I try and edit this node through the drupal node UI.
I am also able to prevent this occurring by manually unsetting the reference from the node to the field collection item before I delete the field collection, as shown above in the first linked comment (unset($node->field_my_field[LANGUAGE_NONE]);). However I do think that this should be done automatically.
Comment #5
Dave ReidSo I created a patch in #1399746: Fatal error if a referenced field collection is deleted to at least prevent entities with deleted referenced field collections from causing this fatal so you can still edit them, but automatically removing orphaned field collections is still a good addition to make.
Comment #6
jmuzz CreditAttribution: jmuzz commentedThere is a bug where using entity_delete or entity_delete_multiple will leave the reference to its field collection in its host. There is a patch for it posted here. #2186689: throws EntityMetadataWrapperException after use entity_delete() for delete an item within field collection I believe it should be working when using $field_collection_item->delete(), but please say something if the patch does not solve the problem.
Comment #7
jmuzz CreditAttribution: jmuzz commented