What's the proper way to programmatically delete one specific field entry for a multi-entry field from one specific entity? (that's specific fields and specific entities, not field types or instances and entity types)
Here's some possibilities I've looked into which don't work:
- Loading the entity with
entity_load()
, setting the field entry to =null or =array(), then saving withfield_attach_update()
. It's the closest I've found but it leaves a zombie null field entry in the database which shows up as a blank row on forms until the form is saved andhook_field_is_empty()
can kick in (hook_field_is_empty()
is configured such that =null or =array() will flag as empty). - Loading the entity with
entity_load()
, unsetting the field entry by key, then saving withfield_attach_update()
. This seems to do nothing - it seems that Drupal interprets the entry not being there as a sign to not modify it. (strangely I also sometimes get maximum query time expiration timeouts when trying this approach) field_attach_delete()
- this is much too blunt: it kills all fields for the entityfield_purge_data()
- better, but still too blunt: it kills all entries of the field, not specific entries
So to clarify, I've got code that finds (and loads) an entity which has a field that has multiple entries, and finds a specific entry on that field that needs to be removed. I want to remove that entry completely, without touching any other entries or any other fields on the entity.