Q:

Change CCK Nodereference View at runtime

I have a CCK nodereference field, displayed as a dropdown, and populated by a view.
I'd like to change that view depending on user permissions.  Can I change the view programmatically before it gets rendered?
I can't do it in hook_form_alter() because CCK isn't available here.
So I set up an #after_build, and inspect here.  But this seems to late.  The #options have already been rendered and there's no view property to change.

A:

Thanks for the sugs.  I prefer to do everything in code so this was my solution.  I just manually loaded the view given some argument, and parsed the results.
function module_form_nodetype_node_form_alter(&$form, &$form_state)
{
    // Manipulate form after build so we have access to CCK
    $form['#after_build'][] = '_form_afterbuild';
}

function _form_afterbuild($form, &$form_state)
{
    // Custom options list for this nodereference
    $arg = user_access('administer nodes') ? false : true; 
    $form['field_fieldname']['nid']['nid']['#options'] = _GetOptions($arg);
}

function _GetOptions($arg=false)
{
    $viewResults = views_get_view_result('view_name', '', $arg);

    $options = array();
    foreach ($viewResults as $row) {
        $optionTitle = $row->title;
        $options[$row->nid] = $optionTitle;
    }

    // Sort options by alpha
    asort($options);

    return $options;
}

