Unwanted redirect when using views
fokke - November 16, 2007 - 21:26
| Project: | CCK Redirection |
| Version: | 5.x-1.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | fokke |
| Status: | reviewed & tested by the community |
Description
Somehow the views module triggers hook_nodeapi(&$node, $op = 'view'...) regardless the way a node is viewed as a list, teaser of full page. This leads to an unwanted redirect to the first redirection found in the list.
This can easily be fixed with the attached patch, where the redirection takes place in hook_menu instead.
function cck_redirection_menu($may_cache) {
if (!$may_cache && arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) {
$node = node_load(arg(1));
$fields = _cck_redirection_get_redirect_fields($node->type);
if(!empty($fields)) {
$field = array_shift($fields);
$data = $node->$field['field_name'];
$url = check_plain($data[0]['value']);
if (!empty($url)) {
if(user_access('bypass redirection')) {
drupal_set_message(t('This node is redirected to a !r', array('!r' => l(t('remote source'), $url))));
} else {
drupal_goto($url);
}
}
}
}
}| Attachment | Size |
|---|---|
| cck_redirection.module.patch | 17.58 KB |

#1
By the way, the patch includes more lines than just the changed ones. The checkout I patched returned a file with crappy linebreaks. to me.
#2
redirecting in hook_menu sounds like a much safer option.
#3
it would be nice to track down the line that is doing this. i know that token module could do this too.
#4
The patch would not apply for me but simply replacing the entire cck_redirection_nodeapi function with the code provided by fokke fixed the problem. I tried creating a patch but ran into the same problems. Either way, it would be nice if this was finally put in an official release since it is a critical problem with views.
#5
The file seems to be using CRLF instead of LF line endings (yuck). Here's an uploaded one with LF endings (assuming textmate did it's job). It also has a small fix to check the node_load because the node might not exist which will result in an error later in the code if it runs.