summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt1
-rw-r--r--content.module16
-rw-r--r--includes/content.token.inc34
-rw-r--r--modules/content_permissions/content_permissions.module10
4 files changed, 35 insertions, 26 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 805740e..a03d3fa 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -37,6 +37,7 @@ CCK 6.2-dev
- #324301 Optionwidgets: check for maximum number of values.
- #320632 Content Copy: Make fields/groups checked for export by default + display the list in an overview table.
- Content Copy: Import / export weights of dnd-enabled non-CCK fields.
+- #327715 Babysit 'invalid foreach' warnings caused by invalid incoming $node objects.
CCK 6.2-rc10
============
diff --git a/content.module b/content.module
index c3f3127..e639d4e 100644
--- a/content.module
+++ b/content.module
@@ -367,7 +367,8 @@ function content_alter(&$node, $teaser = FALSE, $page = FALSE) {
function content_prepare_translation(&$node) {
$default_additions = _content_field_invoke_default('prepare translation', $node);
$additions = _content_field_invoke('prepare translation', $node);
- // Merge module additions after the default ones to enable overriding of field values.
+ // Merge module additions after the default ones to enable overriding
+ // of field values.
$node = (object) array_merge((array) $node, $default_additions, $additions);
}
@@ -375,11 +376,14 @@ function content_prepare_translation(&$node) {
* Implementation of hook_nodeapi().
*/
function content_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
- $type = content_types($node->type);
- if (!empty($type['fields'])) {
- $callback = 'content_'. str_replace(' ', '_', $op);
- if (function_exists($callback)) {
- $callback($node, $a3, $a4);
+ // Prevent against invalid 'nodes' built by broken 3rd party code.
+ if (isset($node->type) && ($type = content_types($node->type))) {
+ // Save cycles if the type has no CCK fields.
+ if (!empty($type['fields'])) {
+ $callback = 'content_'. str_replace(' ', '_', $op);
+ if (function_exists($callback)) {
+ $callback($node, $a3, $a4);
+ }
}
}
}
diff --git a/includes/content.token.inc b/includes/content.token.inc
index 30db6e7..5ce6604 100644
--- a/includes/content.token.inc
+++ b/includes/content.token.inc
@@ -25,22 +25,24 @@ function content_token_values($type, $object = NULL) {
$tokens = array();
if ($type == 'node') {
$node = $object;
- $node->build_mode = 'token';
- $node->content = array();
- content_view($node);
- // The formatted values will only be known after the content has been rendered.
- drupal_render($node->content);
- content_alter($node);
-
- $field_types = _content_field_types();
- $type = content_types($node->type);
- foreach ($type['fields'] as $field) {
- $items = $node->{$field['field_name']};
- $function = $field_types[$field['type']]['module'] . '_token_values';
- if (!empty($items) && function_exists($function)) {
- $token_values = $function('field', $items);
- foreach ($token_values as $token => $value) {
- $tokens[$field['field_name'] .'-'. $token] = $value;
+ // Prevent against invalid 'nodes' built by broken 3rd party code.
+ if (isset($node->type) && ($type = content_types($node->type))) {
+ $node->build_mode = 'token';
+ $node->content = array();
+ content_view($node);
+ // The formatted values will only be known after the content has been rendered.
+ drupal_render($node->content);
+ content_alter($node);
+
+ $field_types = _content_field_types();
+ foreach ($type['fields'] as $field) {
+ $items = $node->{$field['field_name']};
+ $function = $field_types[$field['type']]['module'] . '_token_values';
+ if (!empty($items) && function_exists($function)) {
+ $token_values = $function('field', $items);
+ foreach ($token_values as $token => $value) {
+ $tokens[$field['field_name'] .'-'. $token] = $value;
+ }
}
}
}
diff --git a/modules/content_permissions/content_permissions.module b/modules/content_permissions/content_permissions.module
index 7f2bdc4..a756295 100644
--- a/modules/content_permissions/content_permissions.module
+++ b/modules/content_permissions/content_permissions.module
@@ -17,10 +17,12 @@ function content_permissions_perm() {
*/
function content_permissions_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'view') {
- $type = content_types($node->type);
- foreach ($type['fields'] as $field_name => $field) {
- if (isset($node->content[$field_name])) {
- $node->content[$field_name]['#access'] = user_access('view '. $field_name);
+ // Prevent against invalid 'nodes' built by broken 3rd party code.
+ if (isset($node->type) && ($type = content_types($node->type))) {
+ foreach ($type['fields'] as $field_name => $field) {
+ if (isset($node->content[$field_name])) {
+ $node->content[$field_name]['#access'] = user_access('view '. $field_name);
+ }
}
}
}