Posted by pillarsdotnet on October 5, 2011 at 4:50pm
5 followers
Jump to:
| Project: | Drupal core |
| Version: | 7.x-dev |
| Component: | field system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
| Issue tags: | needs backport to D7 |
Issue Summary
The attached one-line patch removes a bare function_exists() from _field_filter_items() that was missed in the clean-up patch at #497118-154: Remove the registry (for functions).
| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| remove-function_exists-from-_field_filter_items.patch | 544 bytes | Idle | PASSED: [[SimpleTest]]: [MySQL] 33,301 pass(es). | View details |
Comments
#1
History of that line of code:
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.
--- modules/field/field.module 11 Aug 2009 14:59:40 -0000 1.22
+++ modules/field/field.module 12 Aug 2009 23:21:56 -0000
@@ -280,14 +280,15 @@ function field_associate_fields($module)
*/
function field_set_empty($field, $items) {
// Filter out empty values.
- $filtered = array();
$function = $field['module'] . '_field_is_empty';
- foreach ((array) $items as $delta => $item) {
- if (!$function($item, $field)) {
- $filtered[] = $item;
+ if (drupal_function_exists($function)) {
+ foreach ((array) $items as $delta => $item) {
+ if ($function($item, $field)) {
+ unset($items[$delta]);
+ }
}
}
- return $filtered;
+ return $items;
}
/**
@@ -279,15 +305,15 @@
* TODO D7: poorly named...
*/
function field_set_empty($field, $items) {
- // Filter out empty values.
- $filtered = array();
$function = $field['module'] . '_field_is_empty';
+ // We ensure the function is loaded, but explicitly break if it is missing.
+ drupal_function_exists($function);
foreach ((array) $items as $delta => $item) {
- if (!$function($item, $field)) {
- $filtered[] = $item;
+ if ($function($item, $field)) {
+ unset($items[$delta]);
}
}
- return $filtered;
+ return $items;
}
/**
@@ -279,15 +305,15 @@ function field_associate_fields($module)
* TODO D7: poorly named...
*/
function field_set_empty($field, $items) {
- // Filter out empty values.
- $filtered = array();
$function = $field['module'] . '_field_is_empty';
+ // We ensure the function is loaded, but explicitly break if it is missing.
+ drupal_function_exists($function);
foreach ((array) $items as $delta => $item) {
- if (!$function($item, $field)) {
- $filtered[] = $item;
+ if ($function($item, $field)) {
+ unset($items[$delta]);
}
}
- return $filtered;
+ return array_values($items);
}
/**
#2
Already discovered in #977052: Implement hook_hook_info() for Field API hooks
#3
If it's required, is it documented so?
#4
@#3 by chx:
Apparently not, but that is a separate issue.
In fact, none of the hook implementations listed on the Field Types API page state whether they're required or optional.
As noted by bjaspan in #517430-7 (see history above):
This has not yet happened, and probably should be opened as a two-year-old documentation bug.
#5
Thanks! Committed and pushed to 8.x, moving back to 7.x.
#6
Committed and pushed to 7.x. Thanks!
#7
Automatically closed -- issue fixed for 2 weeks with no activity.