summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Stevenson2007-09-28 15:33:00 (GMT)
committer Karen Stevenson2007-09-28 15:33:00 (GMT)
commit6130c745d18911c246b8b3388429440765806e59 (patch)
tree588a864f972e0be1824a6fff22eed4cfa23f0631
parentd94f06273e3c64de6b3cc830806e543414474507 (diff)
Add hook_content_is_empty() function to fields and move handling of empty values to content_field_invoke_default().
-rw-r--r--content.module18
-rw-r--r--content_views.inc2
-rw-r--r--nodereference.module20
-rw-r--r--number.module20
-rw-r--r--text.module21
-rw-r--r--userreference.module20
6 files changed, 54 insertions, 47 deletions
diff --git a/content.module b/content.module
index 1b73434..c6cab76 100644
--- a/content.module
+++ b/content.module
@@ -789,11 +789,23 @@ function _content_field_invoke_default($op, &$node, $teaser = NULL, $page = NULL
}
elseif (count($type['fields'])) {
foreach ($type['fields'] as $field) {
- $node_field = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();
+ $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();
+
+ // Don't save empty items.
+ if ($op == 'presave') {
+ foreach ((array) $items as $delta => $item) {
+ $widget_types = _content_widget_types();
+ $module = $widget_types[$field['widget']['type']]['module'];
+ $is_empty = $module .'_content_is_empty';
+ if ($delta > 0 && $is_empty($item, $field)) {
+ unset($items[$delta]);
+ }
+ }
+ }
$db_info = content_database_info($field);
if (count($db_info['columns'])) {
- $result = content_field($op, $node, $field, $node_field, $teaser, $page);
+ $result = content_field($op, $node, $field, $items, $teaser, $page);
if (is_array($result)) {
$return = array_merge($return, $result);
}
@@ -802,7 +814,7 @@ function _content_field_invoke_default($op, &$node, $teaser = NULL, $page = NULL
}
}
if (isset($node->$field['field_name'])) {
- $node->$field['field_name'] = $node_field;
+ $node->$field['field_name'] = $items;
}
}
}
diff --git a/content_views.inc b/content_views.inc
index 708545b..2bb14e5 100644
--- a/content_views.inc
+++ b/content_views.inc
@@ -144,6 +144,8 @@ function content_views_field_handler_group($field_info, $field_data, $value, $da
foreach ($field_info['content_db_info']['columns'] as $column => $attributes) {
$query_columns[] = "node_data_$field[field_name].$attributes[column] AS $column";
}
+ // Add node.nid to the beginning of the list to keep db_rewrite_sql()
+ // from mistakenly adding DISTINCT to nodereference fields.
$query = "SELECT node.nid, ". implode(', ', $query_columns) .
" FROM {node} node".
" LEFT JOIN {". $field_info['content_db_info']['table'] ."} node_data_$field[field_name] ON node.vid = node_data_$field[field_name].vid".
diff --git a/nodereference.module b/nodereference.module
index 2274498..7beb9fd 100644
--- a/nodereference.module
+++ b/nodereference.module
@@ -153,19 +153,17 @@ function nodereference_field($op, &$node, $field, &$items, $teaser, $page) {
}
}
return;
+ }
+}
- // Don't save empty items.
- case 'presave':
- if (is_array($items)) {
- foreach ($items as $delta => $item) {
- if ($delta > 0 && empty($item)) {
- unset($items[$delta]);
- unset($node->{$field['field_name'][$delta]});
- }
- }
- }
- break;
+/**
+ * Implementation of hook_content_is_empty().
+ */
+function nodeference_content_is_empty($item, $field) {
+ if (empty($item['nid'])) {
+ return TRUE;
}
+ return FALSE;
}
/**
diff --git a/number.module b/number.module
index df6ed3d..46ea275 100644
--- a/number.module
+++ b/number.module
@@ -167,19 +167,17 @@ function number_field($op, &$node, $field, &$items, $teaser, $page) {
}
}
break;
+ }
+}
- // Don't save empty items.
- case 'presave':
- if (is_array($items)) {
- foreach ($items as $delta => $item) {
- if ($delta > 0 && empty($item)) {
- unset($items[$delta]);
- unset($node->{$field['field_name'][$delta]});
- }
- }
- }
- break;
+/**
+ * Implementation of hook_content_is_empty().
+ */
+function number_content_is_empty($item, $field) {
+ if (empty($item['value'])) {
+ return TRUE;
}
+ return FALSE;
}
/**
diff --git a/text.module b/text.module
index fc59f13..832109b 100644
--- a/text.module
+++ b/text.module
@@ -153,21 +153,20 @@ function text_field($op, &$node, $field, &$items, $teaser, $page) {
}
break;
- // Don't save empty items.
- case 'presave':
- if (is_array($items)) {
- foreach ($items as $delta => $item) {
- if ($delta > 0 && empty($item)) {
- unset($items[$delta]);
- unset($node->{$field['field_name'][$delta]});
- }
- }
- }
- break;
}
}
/**
+ * Implementation of hook_content_is_empty().
+ */
+function text_content_is_empty($item, $field) {
+ if (empty($item['value'])) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
* Implementation of hook_field_formatter_info().
*/
function text_field_formatter_info() {
diff --git a/userreference.module b/userreference.module
index 0f1e037..0ace4e5 100644
--- a/userreference.module
+++ b/userreference.module
@@ -77,19 +77,17 @@ function userreference_field($op, &$node, $field, &$items, $teaser, $page) {
}
}
return;
+ }
+}
- // Don't save empty items.
- case 'presave':
- if (is_array($items)) {
- foreach ($items as $delta => $item) {
- if ($delta > 0 && empty($item)) {
- unset($items[$delta]);
- unset($node->{$field['field_name'][$delta]});
- }
- }
- }
- break;
+/**
+ * Implementation of hook_content_is_empty().
+ */
+function userreference_content_is_empty($item, $field) {
+ if (empty($item['uid'])) {
+ return TRUE;
}
+ return FALSE;
}
/**