? destination.patch
Index: nodereference_url.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodereference_url/nodereference_url.module,v
retrieving revision 1.9
diff -u -p -r1.9 nodereference_url.module
--- nodereference_url.module	17 May 2009 00:57:38 -0000	1.9
+++ nodereference_url.module	30 May 2009 23:34:23 -0000
@@ -48,14 +48,26 @@ function nodereference_url_widget_info()
  * Implementation of hook_link().
  */
 function nodereference_url_link($type, $object, $teaser = FALSE) {
+  if ($type == 'node') {
+  }
+}
+
+/**
+ * Internal function to build actual links.
+ *
+ * This can be called by other modules if the links should be displayed in a
+ * block, or in some custom location.
+ */
+function nodereference_url_make_links($object, $teaser) {
   $links = array();
 
-  if ($type == 'node') {
-    $fields = content_fields(NULL, $object->type);
-    foreach ($fields as $field_name => $field) {
-      foreach(_nodereference_url_field_instances($field_name) as $target_type => $instance) {
-        if ($instance['widget']['type'] == 'nodereference_url' && !empty($instance['widget']['node_link']['enabled'])) {
-          if (!empty($field['referenceable_types'][$object->type]) && user_access('create ' . $target_type . ' content')) {
+  $fields = content_fields(NULL, $object->type);
+  foreach ($fields as $field_name => $field) {
+    foreach(_nodereference_url_field_instances($field_name) as $target_type => $instance) {
+      if ($instance['widget']['type'] == 'nodereference_url' && !empty($instance['widget']['node_link']['enabled'])) {
+        if (!empty($field['referenceable_types'][$object->type]) && user_access('create ' . $target_type . ' content')) {
+          if ((!empty($instance['widget']['node_link']['teaser']) && $teaser == TRUE)
+              || (!empty($instance['widget']['node_link']['full']) && $teaser == FALSE)) {
             $links[$target_type .'_'. $field_name] = array(
               'title' => $instance['widget']['node_link']['title'],
               'href' => 'node/add/'. str_replace('_', '-', $instance['type_name']) .'/'. $object->nid,
@@ -63,12 +75,19 @@ function nodereference_url_link($type, $
             if (!empty($instance['widget']['node_link']['hover_title'])) {
               $links[$target_type .'_'. $field_name]['attributes']['title'] = $instance['widget']['node_link']['hover_title'];
             }
+            if (!empty($instance['widget']['node_link']['destination'])) {
+              if ($instance['widget']['node_link']['destination'] == 'source') {
+                $links[$target_type .'_'. $field_name]['query'] = drupal_get_destination();
+              }
+              elseif ($instance['widget']['node_link']['destination'] == 'node') {
+                $links[$target_type .'_'. $field_name]['query'] = 'destination='. urlencode(drupal_get_path_alias('node/'. $object->nid));
+              }
+            }
           }
         }
       }
     }
   }
-
   return $links;
 }
 
@@ -154,6 +173,27 @@ function nodereference_url_widget_settin
           '#default_value' => isset($widget['node_link']['hover_title']) ? $widget['node_link']['hover_title'] : '',
           '#description' => t('Text shown while hovering over the link.'),
         );
+        $form['node_link']['teaser'] = array(
+          '#type' => 'checkbox',
+          '#title' => t('Show on teaser'),
+          '#default_value' => isset($widget['node_link']['teaser']) ? $widget['node_link']['teaser'] : FALSE,
+        );
+        $form['node_link']['full'] = array(
+          '#type' => 'checkbox',
+          '#title' => t('Show on full view'),
+          '#default_value' => isset($widget['node_link']['full']) ? $widget['node_link']['full'] : TRUE,
+        );
+        $form['node_link']['destination'] = array(
+          '#type' => 'select',
+          '#title' => t('Return path'),
+          '#default_value' => isset($widget['node_link']['destination']) ? $widget['node_link']['destination'] : 'default',
+          '#options' => array(
+            'default' => t('The default location'),
+            'node' => t('The node being referenced'),
+            'source' => t('The page the link was clicked on'),
+          ),
+          '#description' => t('The path to return to after creating the node.'),
+        );
       }
       return $form;
 
