node_factory_set_value inserts only 1st letter of text
fobbie - June 8, 2008 - 21:05
| Project: | Node factory |
| Version: | 5.x-1.0-beta2 |
| Component: | Miscellaneous |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Jump to:
Description
Hi
I have been having a hard time with using this module because I don't know php or coding that well. The code below inserts the first letter of the text string into the database. So instead of 'x_location' and 'y_location', the values are 'x' and 'y'. The title comes up as it should.
$edit = node_factory_create_node( 'frame');
node_factory_set_value( $edit, 'title', 'frame_title');
node_factory_set_value( $edit, 'field_photo_x', 'x_location');
node_factory_set_value( $edit, 'field_photo_y', 'y_location');
node_factory_save_node( $edit);I've also put these lines in the node_factory_set_value function to track $value which gives me the full string:
case 'number_integer':
if ( $field['multiple'] == 1) {
$edit[ $name]['keys'][] = $value;
}
else {
$edit[ $name]['key'] = $value;
echo $value;
}
return;Is there something simple that I'm missing or am I just way out there in left field?
Please help.
Thanks
Ken

#1
What cck field type is field_photo_x?
And why are you testing 'number_integer' for it? It's a string right?
#2
I ran into the same thing. Testing with some simple code:
<?php
$title = 'Article Title';
$abstract = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce nisl. Suspendisse potenti. Curabitur tincidun\
t lacus eget lectus. Nunc eget nulla. Ut nec odio sit amet massa scelerisque laoreet. Curabitur rutrum elementum sapien. S\
ed ultrices ipsum non quam. Cras id orci quis risus convallis fermentum. Proin elit mauris, posuere sit amet, vehicula nec\
, ultricies sit amet, quam. Mauris purus. Praesent feugiat lacus eget dui. Nunc in nisl. Suspendisse faucibus, lacus susci\
pit tristique accumsan, tortor velit convallis erat, non convallis elit diam at libero. In feugiat accumsan orci. Nam nec \
odio fringilla lectus tincidunt elementum. Praesent non dolor. Donec lectus dui, fringilla fermentum, tincidunt lacinia, e\
gestas nec, mi. Nulla id nisi. Ut eget sapien.';
$givenname ='John';
$surname = 'Doe';
$email = 'email@education.edu';
$edit = node_factory_create_node( 'article');
node_factory_set_value( $edit, 'title', $title);
node_factory_set_value( $edit, 'field_abstract', $abstract);
node_factory_set_value( $edit, 'field_given_name', $givenname);
node_factory_set_value( $edit, 'field_surname', $surname);
node_factory_set_value( $edit, 'field_email', $email);
node_factory_save_node( $edit);
?>
Produces:
abstract:
L
given_name:
J
surname:
D
email:
e
<?php[...]
node_factory_set_cck_value( $edit, 'title', $title);
node_factory_set_cck_value( $edit, 'field_abstract', $abstract);
node_factory_set_cck_value( $edit, 'field_given_name', $givenname);
node_factory_set_cck_value( $edit, 'field_surname', $surname);
node_factory_set_cck_value( $edit, 'field_email', $email);
node_factory_save_node( $edit);
?>
Produces this error:
* node_factory API change node_factory_set_cck_value !!! Param $value must be an array! Is string* node_factory API change node_factory_set_cck_value !!! Param $value must be an array! Is string
* node_factory API change node_factory_set_cck_value !!! Param $value must be an array! Is string
* node_factory API change node_factory_set_cck_value !!! Param $value must be an array! Is string
* node_factory API change node_factory_set_cck_value !!! Param $value must be an array! Is string
* warning: Invalid argument supplied for foreach() in /var/www/dev/sites/all/modules/cck/text.module on line 388.
* warning: Invalid argument supplied for foreach() in /var/www/dev/sites/all/modules/cck/text.module on line 388.
* warning: Invalid argument supplied for foreach() in /var/www/dev/sites/all/modules/cck/text.module on line 388.
* warning: Invalid argument supplied for foreach() in /var/www/dev/sites/all/modules/cck/text.module on line 388.
* warning: Invalid argument supplied for foreach() in /var/www/dev/sites/all/modules/cck/content.module on line 407.
* warning: Invalid argument supplied for foreach() in /var/www/dev/sites/all/modules/cck/content.module on line 407.
* warning: Invalid argument supplied for foreach() in /var/www/dev/sites/all/modules/cck/content.module on line 407.
* warning: Invalid argument supplied for foreach() in /var/www/dev/sites/all/modules/cck/content.module on line 407.
But no node content.
Of course, I am not claiming/assuming that something is wrong with Node Factory module :-)
But, just hoping I can learn more about how to call cck fields with this module. What are we missing here?
#3
I guess I also see right away that the second example is looking for an array, which does give me a clue there...(working out now)
#4
Ok, so I do see that there should be an array when referencing cck, like this:
<?phpnode_factory_set_cck_value( $edit, 'field_node_ref_auto_single', array( array( 'nid' => 47)));
?>
That makes sense.
Does this work for all cck types, then?
#5
...although, another example from http://drupal.org/project/node_factory shows
<?phpnode_factory_set_value( $edit, 'field_node_ref', 123);
?>
Which of course is a cck field, but is not calling "node_factory_set_cck_value"
So, this is a wee bit confusing.
#6
Update:
Even if I use
<?phpnode_factory_set_cck_value( $edit, 'field_abstract', array( 'key' => $abstract));
?>
Still only prints first letter of the string...