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.

Comments

prom3theus’s picture

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.

prom3theus’s picture

Status: Active » Needs review

Please make a patch after a review if you accapt my request and the re-implemented code below:

function _cck_redirection_divert($element) {
  if (!empty($element['#item']['value'])) {
    $element['#item']['value'] = str_replace('<front>', '', $element['#item']['value']);
    drupal_goto($element['#item']['value']);
  }
}

Regards.

prom3theus’s picture

For a more complate solution, I was modified the module code at line 561, posted code first line is just for context-information:

    if (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.

torsti’s picture

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?

bigjim’s picture

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?

bigjim’s picture

StatusFileSize
new1018 bytes

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']))  {
choster’s picture

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.

tyromind’s picture

thanks prom3theus & jalama. Applied patch @6 working as expected. Running 6.x-1.1 on core 6.8

dboulet’s picture

Works for me too, can we get these changes committed?

tyromind’s picture

Status: Needs review » Reviewed & tested by the community

sounds good to me!

damienmckenna’s picture

StatusFileSize
new471 bytes

Here's an alternative that brings the logic farther back to line 558, i.e. instead of:

  if ($page) {

it now says

  if ($page && $element['#item']['value']) {
BernieCram’s picture

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

guillaumeduveau’s picture

StatusFileSize
new708 bytes

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...

damienmckenna’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new34.68 KB

Here's a cleaned up patch. It also reviews the unnecessary if-statement from line 570.

guillaumeduveau’s picture

This patch removes all the code and puts it back with your modifications, why ?

damienmckenna’s picture

uh... oops.

damienmckenna’s picture

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.

damienmckenna’s picture

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..

damienmckenna’s picture

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).

guillaumeduveau’s picture

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

guillaumeduveau’s picture

Version: 6.x-1.1 » 6.x-1.2
Component: Miscellaneous » Code
Status: Needs review » Fixed

Fixed in 6.x-1.2 !

damienmckenna’s picture

Awesome! :-)

guillaumeduveau’s picture

Thanks to Robin ! Robin, BTW, just tell me if you don't want me to sort the issue queue.

damienmckenna’s picture

Status: Fixed » Needs work

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.

dboulet’s picture

DamienMcKenna, are you still planning on submitting your patch, or can this be marked back to "fixed"?

dboulet’s picture

Status: Needs work » Fixed

A year and a half without a response, so closing this issue. The bug is fixed, any code optimization can be taken care of in another issue.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.