3

I need to recreate the behavior drupal has when you create a translation but programmatically.

Doing $node->addTranslation('de'); on a hook insert create an empty node but I need the field to be filled with the untranslated node content.

Is there a way to achieve this instead of having to repopulate every field from the main node ?

5

addTranslation takes a second parameter, $values:

An array of initial values to be assigned to the translatable fields. Defaults to none.

So in theory you should just need to make use of that parameter, and pass the node's current field values:

$node->addTranslation('de', $node->toArray());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.