I have a profile2 with a field collection field that allows multiple values.
My rule component simply accepts a field collection as a parameter, and deletes the field collection entity with that ID. Executing via passing the field collection ID will remove it when I view the profile, but displays the error: Notice: Trying to get property of non-object in field_collection_field_get_entity() (line 1589 of /Users/amorton/Sites/edge/edge/sites/all/modules/contrib/field_collection/field_collection.module).
Examining the profile in devel shows that the field collection is still listed. The entry is gone from the field_collection_item table in the DB, but still exists in the field_data and field_revision tables.
I have also tried the "Remove an item from a list" action. If I have 2 field collection items saved to the profile, executing the rule using the ID for one will remove BOTH when viewing the profile. However, examining the profile in devel shows that the one I did not remove is still attached. Checking the field's table in the database shows that the item's revision ID is now null. Manually setting it back to match the field ID will bring it back, but I have to clear the cache first.
Comment | File | Size | Author |
---|---|---|---|
#4 | 1968976-delete-action-4.patch | 930 bytes | mortona2k |
#3 | 1968976-delete-action-2.patch | 449 bytes | kscheirer |
Comments
Comment #1
mortona2k CreditAttribution: mortona2k commentedI wrote a custom action that uses field_collection's delete function, and everything worked fine:
Comment #2
kscheirerThanks mortona2k - I added the function above as a patch. Do we need to add a hook_rules_action_info() as well? I'm not too familiar with rules/actions.
Comment #3
kscheirerSorry, patch attached.
Comment #4
mortona2k CreditAttribution: mortona2k commentedHere's your patch with the hook_rules_action_info() filled in. Ultimately, what this patch does is add a rules action "Delete field collection item" in the "Field Collection group"
If possible, I think it would be better to have everything just work when you select "Delete Entity". I wonder if it doesn't due to Field Collection's entity implementation, like something wonky in the delete function not properly extending the parent function.
This patch does work, but you'd have to know to look for this action when you might expect to just use the default delete entity. We may want consider putting this action into the "Entities" rule group, which would place "delete field collection item" right next to "delete entity", making it more obvious.
Comment #5
mortona2k CreditAttribution: mortona2k commentedHere's rules' code for deleting entities. Not sure why the $wrapper->delete() doesn't use field collection's delete function.
The documentation mentions overriding the save/delete functions so that the entity api can pick up the changes, but I don't see what's going wrong:
https://drupal.org/node/878804
Comment #6
jibize CreditAttribution: jibize commentedAfter deleting a field collection through Rules, I was also having the problem with the Host Entity still showing the Field collection but with empty fields inside, like if all the fields within the "supposed to be removed" Field collection have been reset to null but the FC was still here. Applying patch #4 and using the action "delete field collection" worked for me, thanks!
Comment #7
jsibley CreditAttribution: jsibley commentedAny progress on putting this into a release? Thanks.
Comment #8
dgwebcreative CreditAttribution: dgwebcreative commentedI Applied this patch and I am still getting the empty fields when I select "delete field collection item" looping from a field collection list in rules. I'm running the latest dev version.
Comment #9
kristofferwiklund CreditAttribution: kristofferwiklund commentedComment #10
milos.kroulik CreditAttribution: milos.kroulik commentedUsing patch #4 makes no difference for me. The reference to the field collection entity is still there.
Comment #11
Kris77 CreditAttribution: Kris77 commentedI have the same thing as @dgdrupler: "I Applied this patch and I am still getting the empty fields when I select "delete field collection item" looping from a field collection list in rules."
Comment #12
pinueve CreditAttribution: pinueve commentedin my last action in rules, i just 'set a data value', the parent field colection to empty, and in worked, no patch, no nothing.