How can I copy a body field 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.
/**
 * Implements hook_form_alter().
 */
function copy_fields_from_model_contract_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
  
  $nid = 6766;
  $node_storage = \Drupal::entityTypeManager()-&gt;getStorage('node');
  $node = $node_storage-&gt;load($nid);
  if ($nid == '6766') {
    $getcontract = $node-&gt;field_vertragsinhalt-&gt;value;
  }

  $nid = 6716;
  $node_storage = \Drupal::entityTypeManager()-&gt;getStorage('node');
  $node = $node_storage-&gt;load($nid);
  if ($nid == '6716') {
    if ($form_id == 'node_buch_anlegen_edit_form') {
      $node-&gt;field_vertragsinhalt-&gt;value = $getcontract;
      $node-&gt;body-&gt;format = 'full_html';
      $node-&gt;save();
      dpm(&quot;Testsetest&quot;);
    }
  }
}
Use hook_ENTITY_TYPE_prepare_form if you want to change a field value before the form is built for an existing node:
&lt;?php

use Drupal\node\NodeInterface;
use Drupal\Core\Form\FormStateInterface;


/**
 * Implements hook_ENTITY_TYPE_prepare_form() for node entities.
 */
function mymodule_node_prepare_form(NodeInterface $node, $operation, FormStateInterface $form_state) {
  if ($operation == 'edit') {
    if ($node-&gt;id() == '6716') {
      $node-&gt;field_vertragsinhalt-&gt;value = $getcontract;
      $node-&gt;body-&gt;format = 'full_html';
      // don't save the node yet, it will be saved after submitting
    }
  }
}

For the more common case of setting field values when creating new nodes see Pre-populate an entity reference field (media image) when creating a node