Override node reference select list options in node edit form

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';

Syndicate content