Here is a views answer, but I'd still like to know if there is a better or preferred way of doing this. I added a function in my_module:
function my_module_views_pre_render(&$view) {
if ($view->name=='staff_views') { // user redirect
drupal_goto(drupal_get_path_alias('user/'.$view->result[0]->uid));
}
if ($view->name=='pub_by_docid') {
if (count($view->result) == 1) {
$node = node_load($view->result[0]->nid);
$language = language_list()[$node->language];
drupal_goto(drupal_get_path_alias('node/'.$view->result[0]->nid, $node->language), array('language' => $language), 301);
}
}
}
Note that this function is actually redirecting for a view that matches users based on their legacy user id first, and then for a view that matches document id as mentioned originally in my question.
Update: I've updated the code here to reflect the suggestion from J. Reynolds that I include a http response code of 301 to avoid drupals default of 302.
I also found that to get things to work for non-English publications, I needed to add a language option to drupal_goto()
, which needs to be a language object. That is the reason for the line creating the $language
variable.