Hi,

I'm trying to wrote an importer that filter and parse some xml. So far, so good, but when I try to save the result of a simple page in drupal I can't save more than its path, lang and title — the body is discarded each time. It's on Drupal 7.8, with a standard mysql db and php 5.3.8.
The lang module is used with two language, fr and nl

Here's the code (put in a wrapper function) :

$node = new stdClass(); // We create a new node object
$node->nid = null;
$node->type = "page"; // Or any other content type you want
$node->title = $param['title'];
$node->language = $this->lang;
$node->uid = 1; // Or any id you wish
$node->path = array('alias' => $param['path']); // Setting a node path
node_object_prepare($node);

$node->body[$node->language][0]['value'] = $param['content'];
$node->body[$node->language][0]['summary'] = $param['resume'];
$node->body[$node->language][0]['format'] = 'full_html';
$node = node_submit($node); // Prepare node for a submit
node_save($node); // After this call we'll get a nid

$param['content'] contains actually "

nothing

", $this->lang contains 'fr', and $param['resume'] contains ''. I have no error in my logs — I can see the newly created page in the content section of the admin, but the body is always empty — node_load confirm this.

What do I miss ?

Comments

arcanumxiii@gmail.com’s picture

Found the solution : replace $node->language by 'und'. Logical.

maartendbr’s picture

Hi there arcanum,

I ran in the exact same problem, and your solution worked.

But I don't see why it is logical that you leave the body field with an undecided language? I'd rather have it also having the language-property the rest of my saved node has, no?

lex0r’s picture

Subscribe.
Why isn't it possible to set language for newly created nodes?

Simplicity is the ultimate sophistication