Posted by tjferre on January 4, 2013 at 5:22pm
8 followers
| Project: | Field collection |
| Version: | 7.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | major |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
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
Comments
#1
Hi, +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.
#2
I get same issue.
I make patch from tjferre solution.
This patch is part of the #1day1patch initiative.
#3
The last submitted patch, field_collection-non-object-field_collection_field_get_entity-1880312-2.patch, failed testing.
#4
My 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
#5
Should this be closed as a duplicate, then?
#6
You are right. I thought i have did it
#7
Hello,
I have same problem.
I'm trying to delete programmatically some field_collection items and I've getting same error as OP.
<?php$service = field_get_items('node', $node, 'field_our_services');
foreach ($service as $service_item) {
var_dump($service_item);
entity_delete_multiple('field_collection_item', array($service_item));
var_dump(entity_load('field_collection_item',array($service_item)));
?>
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):
array(2) {
["value"]=>
string(2) "60"
["revision_id"]=>
string(2) "95"
}
array(0) {
}
array(2) {
["value"]=>
string(2) "61"
["revision_id"]=>
string(2) "96"
}
array(0) {
}
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.