Having installed the latest dev version to test that the recent commits (including my own #564680: Add support for bulk rebuilds of derivative files in Image module) were working, I am getting the following error repeated over 20 times when creating an image node:
warning: Invalid argument supplied for foreach() in C:\Documents and Settings\admin\My Documents\My Websites\btomcc\sites\all\modules\filefield_paths\filefield_paths.module on line 551
I have added two CCK fields to Image on the system in question but I think the errors are generated for fields that aren't associated with my Image content type.
Specifically I think the problem is in this code:
// Get CCK fields.
if (module_exists('content')) {
$cck = content_fields(NULL, $node->type);
foreach ($cck as $name => $field) {
if ($field['type'] == 'text') {
foreach ($node->{$name} as $key => $value) {
if (isset($node->{$name}[$key]['value'])) {
$fields["{$name}_{$key}"] = &$node->{$name}[$key]['value'];
}
}
}
}
}
As I understand the comments in content.module, content_fields(NULL, $node->type) does NOT return all fields for just $node->type because the first parameter is NULL. It returns all CCK fields in my system (and there are quite a few).
Then when the line foreach ($node->{$name} as $key => $value) { is executed, $name can be a field name that is not instantiated on $node at all.
I will see whether it is enough just to test whether $node->{$name} is set before attempting to apply foreach to it.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | filefield_paths-618598-1.patch | 1.15 KB | sp3boy |
Comments
Comment #1
sp3boy commentedHere is a patch to make the suggested change. Will do a bit more testing as well.
Comment #2
sp3boy commentedThis works with a CCK field on Page and a different one on Image. If the full path of the uploaded file on a test Page node is entered into the CCK field, that field is updated when the node is edited and saved following a change to the path token definition (using the new Update feature).
Comment #3
sp3boy commentedOK, going to mark this issue as a duplicate because there is a neater solution proposed at http://drupal.org/node/606500#comment-2210098.