Brightonart Ltd.
P.O. Box 3416
Brighton BN50 9HQ
Override node reference select list options in node edit form
Submitted by marcus on Thu, 19/05/2011 - 08:39
The requirement is to change the list of options for a node reference cck field to limit the select according to the user. Creating a hook_form_alter in a custom module and do dpm($form) there is no '#options' element in the field. This is because nodereference module adds it's stuff later in the form build process. However there is a way - like so often in Drupal it takes a few web searches to find - and that is '#afterbuild'.
In the hook_form_alter
$form['#afterbuild'][] = 'my_module_custom_function';
This tells forms api to call my_module_custom_function($form, $form_state) after the other modules have added to the form, and the nodereference select options are in the field.