Is there any way to show a "computed field" value in edit mode? I have a content type (Structure) to which I added a text computed field.
In a module I added the following code.
function computed_field_field_reference_compute($entity_type_manager, $node, $fields, $delta) {
  return GedProjectUtils::computeReference($node);
}

It works: In view mode, the field is well calculated.
Now I would like to show this field on edit mode. I added this code to the module.
function gedproject_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'node_structure_edit_form') {
    $form['field_reference']['widget'][0]['value']['#type']='textfield';
    $form['field_reference']['widget'][0]['value']['#title']='Référence';
    $form['field_reference']['widget'][0]['value']['#attributes']['readonly'] = 'readonly';
  }
}

The field is shown empty.



What do I need to change in the code I added?
So the solution found is :
I catched the node id from $form_state and then catched the field value from the node like this :
 /**
 * Implements hook_form_alter
 *
 */
function gedproject_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'node_structure_edit_form') {
    $form_object = $form_state-&gt;getFormObject();
    if ($form_object instanceof EntityForm) {
      $entity = $form_object-&gt;getEntity();
      $value = $entity-&gt;get('field_reference')-&gt;value;
      $form['field_reference']['widget'][0]['value']['#value'] = $value;
      $form['field_reference']['widget'][0]['value']['#type']='textfield';
      $form['field_reference']['widget'][0]['value']['#title']='Référence';
      $form['field_reference']['widget'][0]['value']['#attributes']['readonly'] = 'readonly';
    }
  }
}