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.
field_attach_delete_bundle() calls hook_field_attach_delete_bundle before calling field_delete_instance(), thus before the related instances are actually deleted.
Comment | File | Size | Author |
---|---|---|---|
#8 | fields-period-441180-8.patch | 1.09 KB | bjaspan |
#4 | field-delete-bundle-441180-4.patch | 2.26 KB | bjaspan |
#1 | field-delete-bundle-441180-1.patch | 1.42 KB | bjaspan |
Comments
Comment #1
bjaspan CreditAttribution: bjaspan commentedNote that this is the last hook_field_attach_* hook that is not a pre-hook that is called before the end of its related function.
Comment #2
yched CreditAttribution: yched commentedI think the idea was that if you delete (mark for deletion) the instances first, then the code in hook_field_attach_delete_bundle() cannot use the usual
$instances = field_info_instances($bundle);
to get the instances, because they won't show up.Why is 'call hook first, then mark for delete' problematic ?
Comment #3
yched CreditAttribution: yched commentedOK, got it looking at pbs.module. It does not need to actually do something about the instances in the bundle, just resynchronize according to the *new* state.
What node_type_delete() does is :
- get the type $info
- delete the type
- call the delete hook with the saved info
Maybe we should do the same here ?
- get $instances = field_info_instances($bundle);
- do the delete
- call hook_field_attach_delete_bundle with the saved $instances as a param ?
Comment #4
bjaspan CreditAttribution: bjaspan commentedYes, you got the point exactly. :-) By the way, I just noticed that the PHP docs for hook_field_attach_delete_bundle() specifies that the hook is invoked after the delete operation is performed.
Your proposal looks like it would work, and it turns out we already got $instances earlier in the function. Here's a new patch.
Comment #5
yched CreditAttribution: yched commentedReady, then :-)
Comment #6
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #7
sunIt would be nice to know what "the $bundle" actually is. A string?
Comments should form a proper sentence - with a trailing full-stop (period).
Comment #8
bjaspan CreditAttribution: bjaspan commentedI fixed the missing period in the comment.
$bundle is a string. It is one of the basic data types of Field API, documented elsewhere. We do not declare the types of function arguments in Drupal (though we should) so doing something different for this one function would be inconsistent.
I only added a period, so RTBC.
Comment #9
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks!