N
N
NataliaCh2019-06-28 11:35:50
Drupal
NataliaCh, 2019-06-28 11:35:50

How to programmatically create a node with a multilingual site?

Drupal 7
There is such a standard code for creating a node programmatically:

$node = new stdClass(); 
$node->type = 'journal_number';
node_object_prepare($node); 
$node->title = '2016 №1';
$node->language = 'und';
$node->uid = 1;
$node->status = 1;
$node->field_jyear[$node->language][0]['value'] = 2016;
$node->field_jnumber[$node->language][0]['value'] = "1";
if($node = node_submit($node)) 
    node_save($node);

It works without problems.
But it is worth replacing an undefined language in this code with some other one: or how the fields of the field_jyear and field_jnumber nodes cease to be filled. The node itself is created. And in the right language. But with empty fields. What's wrong here? How to do it right?
$node->language = 'ru';
$node->language = 'en';

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Alexandrov, 2019-06-28
@NataliaCh

Here's the answer:
https://drupal.stackexchange.com/a/36960/7206

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question