I have a question about create node translation programmatically.
First of all, the following is the database screenshot when we use drupal UI to create the translation.
The revision_translation_affected will be set to the language each time when the new one is created.
For example, I create an English article and then translate it with Chinese.
We can see the revision translation affected has been set with the Chinese version because of the translation is the latest created.
However, I use the following code to create a node and add the translation.
$post = \Drupal::entityTypeManager()->getStorage('node')->create(
[
'type' => 'page',
'title' => 'test title',
'langcode' => 'en'
]
);
$post->save();
$source_translation = $post->getTranslation('en');
$target_translation = $post->addTranslation('zh-hant', $source_translation->toArray());
$target_translation->save();
I got the following database result
This result will cause the revision confusion when we want to see the revision record from each translation.
Does anyone have experience on how to handle this issue?