hooks – Drupal Modul Development – Copy bodyfield from one node to another Node

I’m trying to write a small module that copies the body content from one node to another node. The module does almost what it should and everything arrives so far. However, I have to open the node to be copied once, then save it and then open it again. Then it has taken over everything correctly. But I would like to have the field already copied when I open the node. Since this is my beginnings in module development, I would of course appreciate any tips. I am also sure that this can be done more elegantly.


use DrupalnodeEntityNode;
use DrupalCoreFormFormStateInterface;

 * Implements hook_form_alter().
function copy_fields_from_model_contract_form_alter(&$form, FormStateInterface $form_state, $form_id)
//TODO Schleife drum bauen und gleich auf contenttype testen

  $nid = 6766;
  $node_storage = Drupal::entityTypeManager()->getStorage('node');
  $node = $node_storage->load($nid);

  if ($nid == '6766') {
    $getcontract = $node->field_vertragsinhalt->value;

  $nid = 6716;
  $node_storage = Drupal::entityTypeManager()->getStorage('node');
  $node = $node_storage->load($nid);
  if ($nid == '6716') {

    if ($form_id == 'node_buch_anlegen_edit_form') {

      $node->field_vertragsinhalt->value = $getcontract;
      $node->body->format = 'full_html';