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.
I am trying to set a user reference field on a node to have a default value of the currently logged in user. I have tried the following hook_form_alter method but I am not getting anything to populate as the default value (in fact the whole user reference field disappears) .
function modulename_form_equipment_node_form_alter(&$form, &$form_state) {
$form['field_test_reference'][0]['#default_value'] = $user->uid;
}
Any suggestions on how this can be accomplished?
Comments
Comment #1
kidd1126 CreditAttribution: kidd1126 commented$form['#node']->field_test_reference[0]['nid'] = $nid;
may help u