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.
Currently the field_set_empty() function is blindly calling [module]_field_is_empty() without checking that it exists or pulling it in if necessary through drupal_function_exists(). This makes it impossible to put all the field-related hooks in a separate file such as [module].field.inc. This patch wraps the function call in drupal_function_exists().
Comment | File | Size | Author |
---|---|---|---|
#2 | field_check_empty_exists.patch | 932 bytes | quicksketch |
field_check_empty_exists.patch | 864 bytes | quicksketch | |
Comments
Comment #2
quicksketchGood ol' test bot. Now re-indexes the array of $items after dropping entries.
Comment #3
yched CreditAttribution: yched commentedWe definitely miss a drupal_function_exists() to load the file if needed, but I've been trying to resist the 'fail silently' feature in D6.
A field-type module that doesn't implement the hook should be considered broken IMO, and a fatal error at least makes that clear.
Or maybe we can fallback to a reasonable default : field value is empty if (empty($item[$column])) for all columns ?
Comment #4
quicksketchMaybe we could set $items = array(), so no data will save at all and set a watchdog error?
Comment #5
Damien Tournoud CreditAttribution: Damien Tournoud commentedRelated: #332733: Implement a way to require that some functions are available
Comment #6
yched CreditAttribution: yched commentedActually, both 'reasonable default behaviors' mentioned in #3 and #4 have the drawback that they hide errors under the carpet, making them much more difficult to actually detect and fix.
With a 'fatal error, undefined function mymodule_field_is_empty', you can't really ship a broken module ;-)
Comment #7
bjaspan CreditAttribution: bjaspan commentedAssuming hook_field_is_empty() is intentionally a required function to implement the Field Types API, the ideal behavior given a field type module that does not implement it is for the code to fail to compile. Since we can't get that in Drupal, I agree that fatal error is the next best thing. Thus, the current code is correct.
If we want to declare that hook_field_is_empty() is actually optional because there is a reasonable default behavior, that's fine too. I have no opinion about this particular function, yched is the one qualified to have an opinion on it.
I do note the following points:
1. hook_field_is_empty() does not seem to be documented in field.api.inc or http://api.drupal.org/api/group/field_types/7.
2. The Field Type API docs should specify explicitly which hooks are required and which are not.
ISTM that the original point of this issue is a "won't fix" but that we should repurpose the issue for the items above.
Comment #8
quicksketchWhoa, no it is not! Per my original statement:
This is not ideal behavior and nullifies the entire purpose of the function registry. If we intentionally want to break sites we might as well put an exit() in there or call function "goobablygookfunction()".
If you really want to continue calling it even if it doesn't exist, we don't *have* to put it in an IF statement, it's just natural to do so.
Comment #9
bjaspan CreditAttribution: bjaspan commentedRight. My bad; it was late. :-)
Comment #10
yched CreditAttribution: yched commentedre quicksketch: yes, I wrote in #3 "We definitely miss a drupal_function_exists() to load the file if needed" :-)
Comment #12
yched CreditAttribution: yched commentedThis went in with Field UI, and is now dead anyway after the removal of the function autoloader.