D8 form alter to auto populate a default value for og audience

use DrupalnodeEntityNode;
use DrupalCoreFormFormStateInterface;

/**
* Implements hook_form_alter() on behalf of tm_sketch.module.
*/
function YOUR-MODULE-NAEM_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == ‘your form id’) {
$nid = Drupal::request()->query->get(‘nid’);
$node = is_numeric($nid) ? Node::load($nid) : NULL;
$form[‘og_audience’][‘widget’][0][‘target_id’][‘#default_value’] = $node;
}
}

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/2/feed