Well, Im not sure if this is a bug, or if Im not doing things right. This is how you can reproduce

I have a field collection, that has two field, I was trying to delete a specific item within the field collection.


//Load the node wrapper
$wrapper = entity_metadata_wrapper($entity_type, $entity);

//get for example the first element within the field collection
$field_collection_item_value = $wrapper->field_my_field_collection[0]->value();

//use entity delete function for delete the selected item within the field collection
entity_delete('field_collection_item', $field_collection_item_value->item_id);

Well all this code works ok it deletes the item, but when I try to add or delete an item with the links from the node 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).

Any idea how to fix it? Im deleting the wrong way the item within the field collection?

Comments

jmuzz’s picture

Priority: Major » Normal
Status: Active » Needs review
Issue tags: -EntityMetadataWrapperException, -entity_delete, -field collection item
StatusFileSize
new762 bytes

I agree this should be supported.

When a field collection is deleted this way the reference to it in its host remains, which causes the error. There are a couple of ways it could be fixed:

  • hook_delete() is called by the entity API, but the drupal documentation says that this function is for nodes in particular and not generic entities.
  • The patch adds a deletion callback defined in the entity info. This way will probably be more reliable in the long run.
infiniteluke’s picture

#1 works for me. thanks.

ssoulless’s picture

Status: Needs review » Reviewed & tested by the community

Ho yes it worked for me too long time a go in a production site, I forgot to mark this as reviewd by the comunity, #1 patch must be commited, very useful

  • jmuzz committed 77a1df3 on 7.x-1.x
    Issue #2186689: Fixed deletion via entity_delete().
    
jmuzz’s picture

Status: Reviewed & tested by the community » Fixed

Great, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.