I need to add tags as taxonomy terms to already created nodes in 7 languages.
If I do this:
$node = Node::load($nid);
$node->set('field_tags', getTerms($terms));
$node->save();
Just default node in English is updated, however, all terms are created in all languages.
getTerms() - is my own function, which is getting term ids and creating them if they don't exist.
I need to update all node translations. But how?
Tried this:
foreach (getLanguages() as $key => $value) {
$node_translation = $node->addTranslation($key, $node->toArray());
$node_translation->set('field_tags', getTerms($terms));
$node_translation->save();
}
Gives me this error: [error] Invalid translation language (ru) specified.
But 'ru' language is active.
getLanguages() - return array of all languages. The same function is used to create nodes and terms and it's working fine there.
How to update a node and all its translations?