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

prom3theus - November 18, 2008 - 12:18

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

prom3theus - November 18, 2008 - 12:33
Status:active» needs review

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

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

#3

prom3theus - November 18, 2008 - 13:10

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

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

#4

torsti - November 28, 2008 - 17:56

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

jalama - December 4, 2008 - 17:56

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

jalama - December 30, 2008 - 22:47

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']))  {

AttachmentSize
cck_redirection_6_empty.patch 1018 bytes

#7

choster - January 4, 2009 - 01:28

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

tyromind - February 2, 2009 - 01:00

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

#9

dboulet - February 20, 2009 - 18:42

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

#10

tyromind - February 20, 2009 - 21:54
Status:needs review» reviewed & tested by the community

sounds good to me!

#11

DamienMcKenna - March 15, 2009 - 16:47

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

<?php
 
if ($page) {
?>

it now says
<?php
 
if ($page && $element['#item']['value']) {
?>

AttachmentSize
cck_redirection-n335829-empty_value.patch 471 bytes

#12

BernieCram - March 26, 2009 - 02: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

guix - May 26, 2009 - 14:55

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

AttachmentSize
cck_redirection_335829_11.patch 708 bytes

#14

DamienMcKenna - June 24, 2009 - 05:52
Status:reviewed & tested by the community» needs review

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

AttachmentSize
cck_redirection-n335829-v4.patch 34.68 KB

#15

guix - June 24, 2009 - 14:10

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

#16

DamienMcKenna - June 24, 2009 - 15:36

uh... oops.

#17

DamienMcKenna - June 24, 2009 - 15:46

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

DamienMcKenna - June 24, 2009 - 15:54

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

DamienMcKenna - June 24, 2009 - 16:06

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

guix - June 24, 2009 - 18:58

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

guix - June 25, 2009 - 18:44
Version:6.x-1.1» 6.x-1.2
Component:Miscellaneous» Code
Status:needs review» fixed

Fixed in 6.x-1.2 !

#22

DamienMcKenna - June 25, 2009 - 18:46

Awesome! :-)

#23

guix - June 25, 2009 - 18:47

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

#24

DamienMcKenna - June 25, 2009 - 18:53
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.

 
 

Drupal is a registered trademark of Dries Buytaert.