From ac5218d5112a17ca1d1678cafad27868036bef1c Mon Sep 17 00:00:00 2001
From: Victor Kareh <vkareh@vkareh.net>
Date: Fri, 18 Mar 2011 00:45:54 -0400
Subject: [PATCH] Add the option to redirect on node view.

---
 node_destination.module |   51 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/node_destination.module b/node_destination.module
index 8d913ba..e2df3e8 100644
--- a/node_destination.module
+++ b/node_destination.module
@@ -15,12 +15,29 @@ function node_destination_form_alter(&$form, $form_state, $form_id) {
     node_destination_node_settings_form($form);
   }
   elseif (isset($form['#node']) && isset($form['#method']) && $form['#node']->type .'_node_form' == $form_id) {
-    
+    $context = variable_get('node_destination_context_' . $form['#node']->type, 'save');
     $option = node_destination_get_setting($form['#node']->type);
-		
-		if ($option) {
-			$form['#redirect'] = $option;
-		}
+    
+    if ($option && ($context == 'save' || $context == 'both')) {
+      $form['#redirect'] = $option;
+    }
+  }
+}
+
+
+/**
+ * Implementation of hook_nodeapi().
+ */
+function node_destination_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
+  if ($op == 'view' && $page) {
+    $context = variable_get('node_destination_context_' . $node->type, 'save');
+    if ($context == 'view' || $context == 'both') {
+      $option = node_destination_get_setting($node->type);
+      if (module_exists('token')) {
+        $option = token_replace($option, 'node', $form['#node']);
+      }
+      drupal_goto($option);
+    }
   }
 }
 
@@ -47,14 +64,22 @@ function node_destination_node_settings_form(&$form) {
   );
   
   $form['node_destination']['ndest'] = array(
-		'#title' => 'Path to destination',
-	 	'#description' => 'Specify the path a user should be sent to, after adding or editing a node. Simple leave blank to use Drupal\'s default behaviour.',
-   	'#type' => 'textfield',
-   	'#default_value' => node_destination_get_setting($form['#node_type']->type),
+    '#title' => 'Path to destination',
+     '#description' => 'Specify the path a user should be sent to, after adding or editing a node. Simple leave blank to use Drupal\'s default behaviour.',
+     '#type' => 'textfield',
+     '#default_value' => node_destination_get_setting($form['#node_type']->type),
+  );
+  
+  $form['node_destination']['node_destination_context'] = array(
+    '#type' => 'select',
+    '#title' => t('Redirect on node view'),
+    '#description' => t('Select whether the redirection should occur when viewing the node.'),
+    '#options' => array(
+      'save' => t('Only on save'),
+      'view' => t('Only on view'),
+      'both' => t('Both'),
+    ),
+    '#default_value' => variable_get('node_destination_context_' . $form['#node_type']->type, 'save'),
   );
 
 }
-
-
-
-
-- 
1.7.1

