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);
}
}
}
}
}
Comments
Comment #1
fokkezb commentedBy the way, the patch includes more lines than just the changed ones. The checkout I patched returned a file with crappy linebreaks. to me.
Comment #2
moshe weitzman commentedredirecting in hook_menu sounds like a much safer option.
Comment #3
moshe weitzman commentedit would be nice to track down the line that is doing this. i know that token module could do this too.
Comment #4
jmstacey commentedThe 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.
Comment #5
jmstacey commentedThe 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.
Comment #6
binaryreleases commentedTried using both patches, the main one and the one submitted by jmstacey. The official patch gave me a blank page with errors, the updated patch jmstacey worked at first however was causing errors, I tried doing a delete and reinstall and now I can't get the cck forms to appear at all. They don't turn up on the node I want to edit or post and the options for how the redirect works doesn't turn up in manage fields either. I have tried deleting and reinstalling the module a few times and that doesn't seem to be working at all.
any ideas.
running.
Drupal 6
Ubercart
Views
CCK
Comment #7
kbasarab commentedAre there any updates to this?
I tested both the patch and jmstacey's and wasn't able to get either working. I'll jump in and look at the code to see if I can get it going but wanted to see if anyone else has gotten this working with views?
Comment #8
binaryreleases commentedParse error: syntax error, unexpected T_FUNCTION in /etc/drupal/6/sites/all/modules/cck_redirection/cck_redirection.module on line 24
With the official patch I get the above error
With the unofficial patch by jmstacey the field does not appear when you try to edit the node and the options to control the redirect do not appear under manage fields.
any ideas
Just noticed this one, when you created a field for the redirect under the original .module file the field the "Form element to edit the data" box was listed as just text jmstacey patch when you get text field with URI Validation. You also get no redirect options or a field to edit if you create the field
Comment #9
jmstacey commentedI'm still using this on a production site. Do you by chance happen to be running Drupal 6? This patch is for 5.x.
Comment #10
binaryreleases commentedso does anyone have a fix for drupal 6 before I start trying to do redirects at a server level?
Comment #11
binaryreleases commentedDon't worry, just worked out how to do what I wanted using views and the cck link field which makes this entire module irrelevant.
Comment #12
BrockBoland commentedFor what it's worth, I'm seeing this same problem in 6.x-1.2.
I'm including the redirect CCK field in the view, but excluding it from display. It's used by a custom handler on one of the other fields in the view. Even thought the format for the redirect field is set to "Show as Plain Text," it's still redirecting when the view is displayed.
I did some debugging and found that it is calling
theme_cck_redirection_formatter_plain(). This function calls_cck_redirection_redirect(). THAT function looks to$widget['redirect_type']to decide how to handle the redirect. I think this value should be set toCCK_REDIRECTION_NONEwhen it's being formatted as plain text, so that it it doesn't execute one of the_cck_redirection_{method}functions.On my site, I removed the call to
_cck_redirection_redirect()fromtheme_cck_redirection_formatter_link()andtheme_cck_redirection_formatter_plain(). It seems like neither of these theme functions needed to be calling_cck_redirection_redirect(), and they still return the correct value. The patch for this is attached.Comment #13
BrockBoland commentedComment #14
firebus commentedBrockBoland's patch in #12 doesn't apply for me with 6.x-1.2.
Making the same changes in code does fix the issue.
However, does this patch break the desired behavior when Redirection type is set to delay instead of divert? In the delay case, we might want to show the link as a URL or plain text, but still redirect after a delay.
I think the previous strategy of using hook_menu instead of hook_nodeapi might be a better one...
Thanks for your work on this!