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.
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?
Comment | File | Size | Author |
---|---|---|---|
#1 | field_collection-entity_delete-2186689-1.patch | 762 bytes | jmuzz |
Comments
Comment #1
jmuzz CreditAttribution: jmuzz commentedI 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:
Comment #2
infiniteluke CreditAttribution: infiniteluke commented#1 works for me. thanks.
Comment #3
ssoulless CreditAttribution: ssoulless commentedHo 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
Comment #5
jmuzz CreditAttribution: jmuzz commentedGreat, thanks!