Node add form set entity reference default selection based on content from another type node I wrote module with hook_form_alter to modify node_forum_form, i.e., node/add/forum form. One forum field is a taxonomy entity reference, field_topic. I want to set the field_topic selection based on the value from a specific node (NID=77) of type current_topic, which also has field_topic as an entity ref.

field_topic is ref to Topic taxonomy.

After loading node 77, I got the TID of the current_topic field_topic, loaded the term, and then got the term name. Name is displayed on the form above the title using $form['title']['#markup'].

Problem:  Before returning the form, how can I set the form default selection to be that same field_topic value?

use Drupal\taxonomy\Entity\Term;
use Drupal\Core\Form\FormStateInterface;

function MYMODULE_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {

  if ($form_id != 'node_forum_form') {
    return FALSE;
  }
  else {
    $nid = 77;
    $node = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;load($nid);

    $current_topic_id = $node-&gt;get('field_topic')-&gt;getString(); //get the TID
    $term = Term::load($current_topic_id);
    $the_topic = $term-&gt;getName();

    $form['title']['#markup'] = t('&lt;h3&gt;The Current Topic is:  &lt;i&gt;' . $the_topic . '&lt;/i&gt;&lt;/h3&gt;');

    // REPLACE THE NEXT LINE WITH CODE TO SET THE CURRENT TOPIC
    $form['field_topic']['widget']['#options']['_none'] = 'Click &amp; Select the Current Topic';

    return $form;
  }
}
I suppose with 


  set the form selection


you mean the default value of the taxonomy term reference field?

If yes, in the code above try this:

$form['field_topic']['widget']['#default_value'] = $term-&gt;tid();


Btw. you also want to change your implementation from MYMODULE_form_alter to MYMODULE_form_node_forum_form_alter, because the former hook will be called for all forms, whereas the latter is just called when the forum node form renders.