Using Text CCK field with multiple role-dependant "show" trims.
warning: Invalid argument supplied for foreach() in sites/all/modules/option_trim/option_trim.module on line 112.
Specifically,
if ($relationship['preserve_values']) {
foreach ($pre_saved_node->{$relationship['field2']} as $old_option) { //Error here
$old_options[] = $old_option[key($field2_info['columns'])];
}
}
Probable fix (untested)
Line 92
$relationships = _option_trim_relationships($node->type);
++if($node->nid > 0) //Don't load the old one if there isn't any. Should this be if(empty($node->nid)) ?
$pre_saved_node = node_load($node->nid);
foreach ($relationships as $key => $relationship) {
...
$old_options = array();
--if ($relationship['preserve_values']) {
++if ($relationship['preserve_values'] && !empty($pre_saved_node)) {
foreach ($pre_saved_node->{$relationship['field2']} as $old_option) {
As it is, the value still ends up saving.
Comments
Comment #1
RoboPhred commentedComment #2
RoboPhred commentedFixed it and rolled a patch. Since "$pre_saved_node" is only used in the preserve_values case, I moved it into there. This also saves a node_load call that might not be needed.
Comment #3
RoboPhred commentedComment #4
RoboPhred commentedComment #5
cyu commentedI kept the node_load outside of the loop on all trims. Even though node_load will cache it, I wanted to only make one call to node_load (which it will still make even if there are no preserved value relationships for that content type). The warning should be gone though with http://drupal.org/cvs?commit=183012
Thanks.