No redirect if field is blank
prom3theus - November 18, 2008 - 12:14
| Project: | CCK Redirection |
| Version: | 6.x-1.2 |
| Component: | Code |
| Category: | feature request |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | needs work |
Description
Hello, I think that if a user leaves a field on blank/empty, in the most cases that's happens because he/her do not want to add a value. If no value, nothing to do - nor? So I suggest that, if user do not add a value, submited content do not go to the front page. For redirect to front page, I suggest to use the official Drupal method "" instead of empty string.
Regards, thank You.

#1
Correction for "Drupal method "" instead of empty string."
Drupal method "<front>" instead of empty string.
Buggy tracker don't change the HTML special chars, argh.
#2
Please make a patch after a review if you accapt my request and the re-implemented code below:
<?phpfunction _cck_redirection_divert($element) {
if (!empty($element['#item']['value'])) {
$element['#item']['value'] = str_replace('<front>', '', $element['#item']['value']);
drupal_goto($element['#item']['value']);
}
}
?>
Regards.
#3
For a more complate solution, I was modified the module code at line 561, posted code first line is just for context-information:
<?phpif (user_access('bypass redirection')) {
if (!empty($element['#item']['value'])) {
$element['#item']['value'] = str_replace('<front>', '', $element['#item']['value']);
drupal_set_message(t('This node is redirected to a !r.', array('!r' => l(t('remote URI'), $element['#item']['value']))));
}
?>
If redirection field's value is empty, redirection information message doesn't appears.
#4
Hello, I tried the code above and replacement and redirection info message hiding works ok. Though I'm desperately needing the most important feature, "do nothing if field is empty". Why redirection should always be directed to front page?
This cck field would be so fine addition to normal page insert - you could easily redirect pages when needed without messing with menu system.
prom3theus, can you enhance your code to do that?
#5
If I'm not mistaken the auto-forwarding to front page is a change form the D5 version of cck re-direct correct? why change this behavior?
#6
Here is a patch that incorporates #3 and fixes the original issue posed by prom3thues. The crux of the additional fix is simply changing line 570 (in the current 6.x.1.1 version) from
} else {to
} elseif (!empty($element['#item']['value'])) {#7
The patches at prom3theus @3 and jalama @6 work well for me. though I had to edit them manually. Are they to be applied to HEAD or 6.x-1.1? I am using 1.1 straight from CVS and my line numbers are completely different, and so I cannot make a clean patch. The HEAD version, however, doesn't even have 500 lines in it.
#8
thanks prom3theus & jalama. Applied patch @6 working as expected. Running 6.x-1.1 on core 6.8
#9
Works for me too, can we get these changes committed?
#10
sounds good to me!
#11
Here's an alternative that brings the logic farther back to line 558, i.e. instead of:
<?phpif ($page) {
?>
it now says
<?phpif ($page && $element['#item']['value']) {
?>
#12
I have applied Jamala's patch and CCK Redirection module now seems to be working for me as expected. Thanks for this because it was starting to redirect things to front every time I went in to edit stories older than the installation of the module.
I have not applied a patch before and followed instructions here: http://drupal.org/node/60818
Bernie
#13
DamienMcKenna's method in #11 works nicely but strangely his patch won't apply at least for me. Here's a new patch. It would be nice to see this commited...
#14
Here's a cleaned up patch. It also reviews the unnecessary if-statement from line 570.
#15
This patch removes all the code and puts it back with your modifications, why ?
#16
uh... oops.
#17
Seems like it's a line ending issue.. Nano says that the file in CVS was saved in DOS/Windows format (CRLF) while my patch was to make it LF (UNIX/OSX). Note that all files in CVS *should* be saved as LF.
#18
I've created an issue & patch to take care of the line endings issue: #501024: Code in CVS is saved with the wrong line ending format. Not sure if it will specifically work due to the weirdness of line endings vs patches..
#19
The patch in #13 misses another change from the current CVS checkout, e.g.:
Index: cck_redirection.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck_redirection/cck_redirection.module,v
retrieving revision 1.1.4.2
diff -u -p -b -r1.1.4.2 cck_redirection.module
--- cck_redirection.module 31 Oct 2008 21:51:55 -0000 1.1.4.2
+++ cck_redirection.module 24 Jun 2009 15:58:05 -0000
@@ -558,7 +558,7 @@ function _cck_redirection_redirect(&$ele
$method = NULL;
- if ($page) {
+ if ($page && $element['#item']['value']) {
$node = $element['#node'];
$field = content_fields($element['#field_name'], $node->type);
$widget = $field['widget'];
@@ -566,9 +566,7 @@ function _cck_redirection_redirect(&$ele
$method = is_numeric($widget['redirect_type']) ? $widget['redirect_type'] : NULL;
if (user_access('bypass redirection')) {
- if (!empty($element['#item']['value'])) {
- drupal_set_message(t('This node is redirected to a !r.', array('!r' => l(t('remote URI'), $element['#item']['value']))));
- }
+ drupal_set_message(t('This node is redirected to a !r.', array('!r' => l(t('remote URI'), $element['#item']['value']))));
} else {
switch ($widget['redirect_type']) {
case CCK_REDIRECTION_DIVERT:
Unfortunately, because the files in CVS are messed up with incorrect line endings I can't provide a proper patch (see above).
#20
Yes Damien, I realized this afternoon that your patch in #13 would not apply since I had not the latest CVS. Well I have issues with line ends too and need to read something about Drupal patches and that issue, if I found something.
Anyway I've applied for CVS access in order to move on with the module, commit all these patches and release and new version. Wait and see. Or would you like to do it ?
See you,
Guix
#21
Fixed in 6.x-1.2 !
#22
Awesome! :-)
#23
Thanks to Robin ! Robin, BTW, just tell me if you don't want me to sort the issue queue.
#24
While the change in CVS will strictly work, it has four times the validation necessary. I'll provide a cleaner patch that just needs one validation change based on my patch above.