Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By khurrami on
use Drupal\node\Entity\Node;
use Drupal\Core\Form\FormStateInterface;
/**
* 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;
}
}
Comments
=-=
per https://www.drupal.org/node/643758 please edit your post and move it to the 'post installation' forum. Thank you.