I am programmatically creating some content during profile installation and since Drupal uses "en" langcode during this period I am getting the language from config and it is working fine.
The issue I have is that I am creating a node and I will end up with it being in English. So I have set the "langcode" property of the node during creation which worked as expected. But the fields are not responding to this fact(I have only the body field attached).
So I have tried to key the value(s) by the langcode(Drupal 7 style) but it resulted in the field not being populated in DB at all.
The node entity nor field item list nor field item have methods for setting the langcode so I am unsure how to proceed with this.
Any ideas?
This is my code:
// Create 'terms of service' page
$tos = entity_create('node', [
'type' => 'page',
'title' => t('Terms of service', [], ['langcode' => $langcode]),
'uid' => 1,
'status' => 1,
'langcode' => $langcode, // this is working on node only
'defaultLangcode' => $langcode, // no change on field
'activeLangcode' => $langcode, // no change on field
'body' => [
$langcode => [ // this is not working
[
'value' => '<p>' . t('This is a placeholder. Please edit this page and use your own text.', [], ['langcode' => $langcode]) . '</p>',
'summary' => '',
'format' => FULL_HTML_FORMAT
]
]
]
]);
$tos->save();
I have found setLangcode() method on the FieldItemList but that didn't work as well.
I have tried to save the node without body, then set the body and save the node again, but the field is in English again(and the node in installed language). Is it possible that this is kind of a (edge case)bug that relates to language manager?
I have checked the entity constructor and this is also not working:
'body' => [
$langcode => [
[
'value' => [
'value' => 'some text',
'summary' => '',
'format' => FULL_HTML_FORMAT
]
]
]
]