Skip to main content
1 of 3
Rob
  • 341
  • 2
  • 14

No body text saved when creating a node with I18n and specific language set

I'm creating a event type nodes, using data from an external database. It's a multi-lingual site, and the primary language is english.

My code creates the node correctly, when the language is set to LANGUAGE_NONE, but when it is set to "en", the body text is not saved in the database.

foreach ($results as $record) {
  echo '<br/>Creating event: ' . $record->name;
  
  $node = new stdClass();
  $node->type = 'event';
  $node->uid = 1;
  node_object_prepare($node);
  
  $node->title    = $record->name;
  $node->language = "en";
  //$node->language = LANGUAGE_NONE;
  
  $node->body[$node->language][0]['value'] = 'This is a body text for '.$record->name;
  $node->body[$node->language][0]['summary'] = 'Here goes a summary for '.$record->name;
  $node->body[$node->language][0]['format'] = 'raw';
  
  $path = 'content/programmatically_created_node_' . date('YmdHis');
  $node->path = array('alias' => $path);
  
  $instance = field_info_instance('node', 'body', 'event');
  print_r($instance);

  $node = node_submit($node);
  node_save($node);  
  dpm($node);
}

When $node->language = LANGUAGE_NONE, a record is created in the fields_data_body table. I can see the body text, but cannot translate it. I guess this is correct.

But when $node->language = "en", no record is created. This is my problem. I need this set to "en" as it's a multi-lingual site, and without it, there is no "translate" tab when editing the node (Internationalization module drupal.org/project/i18n)

There is some back history to this issue here.. No "body" when creating a node programatically, with Internationalization ..but it's not essential to read it.

Rob
  • 341
  • 2
  • 14