Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I get the following error when viewing a node with a field collection that had items deleted using entity_delete('field_collection_item', $field_collection_item_value);
Notice: Trying to get property of non-object in field_collection_field_get_entity() (line 1589 of /****/modules/field_collection/field_collection.module).
I addressed the issue by checking if $entity->revision_id was set.
<?php
if(isset($entity->revision_id)) {
if ($entity->revision_id != $item['revision_id']) {
// A non-default revision is a referenced, so load this one.
$entity = field_collection_item_revision_load($item['revision_id']);
}
}
?>
If I deleted the item then why would it be trying to look for a revision id?
Thanks,
TJ
Comment | File | Size | Author |
---|
Comments
Comment #1
Striky2 CreditAttribution: Striky2 commentedHi, +1
I get the exact same issue after manually deleting the old revisions attached to a node. Whilst editing the latest version of the node, all the contents of field collections are empty.
Comment #2
GoZ CreditAttribution: GoZ commentedI get same issue.
I make patch from tjferre solution.
This patch is part of the #1day1patch initiative.
Comment #4
GoZ CreditAttribution: GoZ commentedMy patch fail tests, but trying to fix it, i found existing patch for revisions which fix this issue (and issue for revisions) : http://drupal.org/node/1316162#comment-6827200
Comment #5
Simon Georges CreditAttribution: Simon Georges commentedShould this be closed as a duplicate, then?
Comment #6
GoZ CreditAttribution: GoZ commentedYou are right. I thought i have did it
Comment #7
jaroslaw.kaminski CreditAttribution: jaroslaw.kaminski commentedHello,
I have same problem.
I'm trying to delete programmatically some field_collection items and I've getting same error as OP.
this is my code. There is no difference if you use $service_item or $service_item['value'] in entity_delete_multiple.
var_dumps giving ( after several code runs too):
so entity_delete_multiple remove items only partial. Deleting main object of entity but some of things are still on node.
In previous versions of field_collections evrything was fine, I think revision system complicated situation.
Comment #8
vbouchetHi,
I have updated the patch to make it workable with the last version of field_collection (7.x-1.0-beta5).
For an unknown reason, field_collection_field_get_entity is sometimes called with unexisting items. That means the field_collection_item_load retrieve FALSE and create a Notice on the next line because of ->revision_id.
Comment #9
dmsmidtPrevious patch failed to apply for me on the beta5.
Manually patched against latest -dev.
Comment #10
brandy.brown CreditAttribution: brandy.brown commented#9 worked perfectly for me with beta5. Thank you!
Comment #11
ivanhelguera CreditAttribution: ivanhelguera commented+1 here as well :-)
Comment #12
ssoulless CreditAttribution: ssoulless commentedAfter apply patch in #9 the notice disappeared. But when I try to create a new item, or update the field collection I get this error
EntityMetadataWrapperException: Unable to get the data property field_cantidad_salida as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (line 438 of /home/servilla/public_html/servillantasgiraldo.com.co/sites/all/modules/entity/includes/entity.wrapper.inc).
Comment #13
jmuzz CreditAttribution: jmuzz commentedIf I understand correctly, this is about using entity_delete and entity_delete_multiple to remove field collections, right? The reason field_collection_field_get_entity gets called is that the host entity still has a reference to the deleted field collection after the entity is deleted this way. I really don't think a patch for field_collection_field_get_entity is the right approach. That reference should be removed instead. I posted a patch that should accomplish this in #2186689: throws EntityMetadataWrapperException after use entity_delete() for delete an item within field collection. Please give it a try. Maybe one of these can be closed as a duplicate.
Comment #14
heddnThis seems a duplicate to #1822844: Notice: Undefined index: revision_id in field_collection_field_get_entity() (line 1586 of field_collection/field_collection.modu
Comment #15
heddn