Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
field system
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
8 Sep 2009 at 20:19 UTC
Updated:
23 Sep 2009 at 11:40 UTC
Jump to comment: Most recent file
field_delete_{field,instance}() does not invoke hook_field_delete_{field,instance}().
Also, field_delete_field() marks all instances as deleted without even calling hook_field_storage_delete_instance() for them. ISTM that field_delete_field() should call field_delete_instance() for all instances before deleting the field.
These fixes are required for per-bundle storage and other non-default storage engines to work.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | field-delete-hooks-571934-5.patch | 3.28 KB | bjaspan |
| #1 | field-delete-hooks-571934-1.patch | 2.76 KB | bjaspan |
Comments
Comment #1
bjaspan commentedPatch attached.
Comment #2
yched commentedMakes sense, code is fine. As the
TODO: not implementednotes in field.api.php show, we always had the intention to have those hooks...Kind of beats me why we chose field_delete_field($field_name) and field_delete_instance($field_name, $bundle_name) instead of $field and $instance param arrays like for the create and update functions, but that's probably not something to be changed in this thread, and the patch stays consistent with the current API.
Comment #4
bjaspan commentedActually, I'm not sure this patch is right.
Should hook_field_delete_{field,instance} be called before or after the Field API cache is updated to reflect the deletion? If we invoke it before, then calls to field_info_* functions will still return the "deleted" field/instance, which is a problem if (like pbs.module) you want to act on all existing fields/instances. If we invoke it after, then the field/instance is already deleted, and the hooks have no way to access the deleted instance at all (though it can access the deleted field by id).
Comment #5
bjaspan commentedyched reminded me of the general strategy: Call deletion hooks after the object in question is deleted and the cached cleared, and pass the deleted object (which may no longer be available from the Field Info API) as an argument to the hook.
New patch.
Comment #6
yched commentedGreen tests, RTBC.
Comment #7
dries commentedLooks good to me. Committed to CVS HEAD. Thanks!