Hello.
There is a problem. There is a multilingual node type with many translations? English is the default language.
And one needs to change the content of a field on some (not all) non-English translations upon changing this field on the English translation of the node.
I'm trying to do it using the hook_node_update hook (a variant of the hook_entity_update hook).
function my_module_node_update(NodeInterface $node) {
if ($node->bundle() != 'my_bundle' || $node->language()->getId() != 'en') {
return;
}
$langcodes = ...
foreach ($langcodes as $langcode) {
$translation = $node->getTranslation($langcode);
$translation->set('my_field', $my_value);
$translation->save();
}
}
It has worked successfully, but after updating all the translations the translation with "x-default" language is also executing. And this translation doesn't have the `$node->original` property. As I understood, this property has been unset before on saving translations.
Unfortunately, other hooks, executing after this one, can require this property in their code.
As a result, they get NULL instead and causes an error.
In general, I can store and reassign this property forcibly, but it can be called "shamanism".
Could you clarify for me, whether I can update node translations in the hook_node_update? Or how can I do it to avoid the error?