2

I cannot programmatically create a node in anything other than en language.

My site has 3 languages:

  • en
  • fr
  • de

And the code for creating a node is:

define('DRUPAL_ROOT', ...); 
require_once DRUPAL_ROOT . 'includes/bootstrap.inc'; 
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 

$node = new stdClass();
$node->type = "foobar";
node_object_prepare($node);
$node->title = 'test title';
$node->uid = 1;
$node->language = 'fr'; // *** this doesn't seem to work

if ($node = node_submit($node)) {
  node_save($node);
}

No matter what I type in the $node->language = '...'; the result is always the same. The node is created in the English language. I confirm that via looking at admin/content.

I've even tried stuffing this variable with a proper language object which I got out of the enabled languages of my site:

$languages = language_list('enabled');
$lang = $languages[1]['de'];
$node->language = $lang;
  • 1
    As side note, node_submit() always returns the parameter passed to the function; there is no need to check the value returned from the function. – kiamlaluno Jul 25 '12 at 13:39
2

The behavior was an unfortunate side-effect of the admin_language module and the setting Force use of default language.

The "offending" code is at http://drupalcode.org/project/admin_language.git/blob/0167e36c45661502ee6907a5b2b7cad8538b19cf:/admin_language.module#l112

Disabling this options solves the issue.

| improve this answer | |
-1

Some of the hooks might not be firing, instead of node_save($node), try drupal_execute($form_id, $form_state)

That last link was bad... lullabot's should help:

http://www.lullabot.com/articles/quick-and-dirty-cck-imports

doh... drupal 7. Looks like they have changed it to drupal_form_submit

http://www.lukaswhite.com/blog/post/2011/drupal-7-drupal_execute-has-gone-say-hello-to-drupal_form_submit

| improve this answer | |
  • Thanks for the answer. I've seen that sometimes people do suggest drupal_form_submit instead of node_save but I'd really like to know if and how this simple task (saving non English) can be achieved with node_save. – cherouvim Jul 25 '12 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.