diff --git nodereference_url.info nodereference_url.info
index 997a9dd..4cbf091 100644
--- nodereference_url.info
+++ nodereference_url.info
@@ -1,6 +1,6 @@
 ; $Id: nodereference_url.info,v 1.1 2009/01/22 02:25:29 quicksketch Exp $
 name = Node Reference URL Widget
 description = Adds an additional widget to the CCK Node Reference field that prepopulates a reference by the URL.
-dependencies[] = nodereference
-package = CCK
-core = 6.x
\ No newline at end of file
+dependencies[] = node_reference
+files[] = nodereference_url.module
+core = 7.x
diff --git nodereference_url.install nodereference_url.install
deleted file mode 100644
index 7cf6496..0000000
--- nodereference_url.install
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-// $Id: nodereference_url.install,v 1.2 2009/07/25 23:40:04 quicksketch Exp $
-
-/**
- * @file
- * Implementation of hook_install().
- */
-function nodereference_url_install() {
-  drupal_load('module', 'content');
-  content_notify('install', 'nodereference_url');
-}
-
-/**
- * Implementation of hook_uninstall().
- */
-function nodereference_url_uninstall() {
-  drupal_load('module', 'content');
-  content_notify('uninstall', 'nodereference_url');
-}
-
-/**
- * Implementation of hook_enable().
- *
- * Notify content module when this module is enabled.
- */
-function nodereference_url_enable() {
-  drupal_load('module', 'content');
-  content_notify('enable', 'nodereference_url');
-}
-
-/**
- * Implementation of hook_disable().
- *
- * Notify content module when this module is disabled.
- */
-function nodereference_url_disable() {
-  drupal_load('module', 'content');
-  content_notify('disable', 'nodereference_url');
-}
-
-/**
- * Update 'enabled' widget setting to handle teaser and full views separately.
- */
-function nodereference_url_update_6100() {
-  module_load_install('content');
-  module_load_include('inc', 'content', 'includes/content.admin');
-  module_load_include('inc', 'content', 'includes/content.crud');
-
-  $ret = array();
-
-  content_clear_type_cache(TRUE);
-
-  // Grab the list of fields to update.
-  foreach (content_types_install() as $type_name => $fields) {
-    foreach ($fields as $field) {
-      if ($field['type'] == 'nodereference' && $field['widget']['type'] == 'nodereference_url') {
-        // Widgets are each updated individually.
-        if (isset($field['widget']['node_link']['enabled'])) {
-          $field['widget']['node_link']['teaser'] = TRUE;
-          $field['widget']['node_link']['full'] = TRUE;
-          $field['widget']['node_link']['destination'] = 'default';
-          unset($field['widget']['node_link']['enabled']);
-
-          content_field_instance_update($field);
-          $ret[] = array('success' => TRUE, 'query' => t('Updated widget settings for @name.', array('@name' => $field['field_name'])));
-        }
-      }
-    }
-  }
-
-  content_clear_type_cache(TRUE);
-
-  return $ret;
-}
-
diff --git nodereference_url.module nodereference_url.module
index 9592278..4651178 100644
--- nodereference_url.module
+++ nodereference_url.module
@@ -7,18 +7,7 @@
  */
 
 /**
- * Implementation of hook_theme().
- */
-function nodereference_url_theme() {
-  return array(
-    'nodereference_url' => array(
-      'arguments' => array('element' => NULL),
-    ),
-  );
-}
-
-/**
- * Implementation of hook_form_alter().
+ * Implements of hook_form_alter().
  */
 function nodereference_url_form_alter(&$form, &$form_state, $form_id) {
   if ($form_id == 'content_field_edit_form' && isset($form['#field']) && $form['#field']['widget']['type'] == 'nodereference_url') {
@@ -30,28 +19,36 @@ function nodereference_url_form_alter(&$form, &$form_state, $form_id) {
 }
 
 /**
- * Implementation of hook_widget_info().
+ * Implements of hook_widget_info().
  */
-function nodereference_url_widget_info() {
+function nodereference_url_field_widget_info() {
   return array(
     'nodereference_url' => array(
       'label' => t('Reference from URL'),
-      'field types' => array('nodereference'),
-      'multiple values' => CONTENT_HANDLE_MODULE,
-      'callbacks' => array(
-        'default value' => CONTENT_CALLBACK_NONE,
+      'description' => t('Node Reference calculated from URL'),
+      'field types' => array('node_reference'),
+      'settings' => array(
+        'fallback' => NULL,
+        'node_link' => array(),
       ),
+      'behaviors' => array(
+        'multiple values' => FIELD_BEHAVIOR_DEFAULT,
+        'default value' => FIELD_BEHAVIOR_DEFAULT,
+      ), 
     ),
   );
 }
 
 /**
- * Implementation of hook_link().
+ * Implements of hook_node_view().
  */
-function nodereference_url_link($type, $object, $teaser = FALSE) {
-  if ($type == 'node') {
-    return nodereference_url_build_all_links($object, $teaser);
-  }
+function nodereference_url_node_view($node, $view_mode, $langcode) {
+  $links = nodereference_url_build_all_links($node, $view_mode);
+  $node->content['links']['nodereference_ur'] = array(
+    '#theme' => 'links__node__nodereference',
+    '#links' => $links,
+    '#attributes' => array('class' => array('links', 'inline')),
+  );
 }
 
 /**
@@ -64,15 +61,17 @@ function nodereference_url_link($type, $object, $teaser = FALSE) {
  * @return
  *   An array of links for use with theme_links().
  */
-function nodereference_url_build_all_links($node, $teaser) {
+function nodereference_url_build_all_links($node, $view_mode) {
   $links = array();
-  $fields = content_fields();
-  foreach ($fields as $field_name => $field) {
-    foreach (_nodereference_url_field_instances($field_name) as $target_type => $instance) {
+  //check if the type is one of referenced fields.
+  $fields = field_info_instances('node');
+  foreach ($fields as $target_type => $field) {
+    foreach ($field as $field_name => $instance) {
       if ($instance['widget']['type'] == 'nodereference_url') {
-        $link_settings = $instance['widget']['node_link'];
-        if (($link_settings['teaser'] && $teaser == TRUE) || ($link_settings['full'] && $teaser == FALSE)) {
-          if ($link = nodereference_url_build_link($node, $instance, $teaser)) {
+        $link_settings = $instance['widget']['settings']['node_link'];
+        if ( $link_settings[$view_mode] ) {
+          $link = nodereference_url_build_link($node, $instance, $view_mode);
+          if ($link) {
             $links[$target_type .'_'. $field_name] = $link;
           }
         }
@@ -99,27 +98,26 @@ function nodereference_url_build_all_links($node, $teaser) {
  * @return
  *   An array containing properties to build a single link.
  */
-function nodereference_url_build_link($node, $field, $teaser = FALSE) {
+function nodereference_url_build_link($node, $field, $view_mode) {
   $link = array();
 
   // Check if this widget is using a views listing.
-  if (module_exists('views') && !empty($field['advanced_view']) && $field['advanced_view'] != '--') {
-    $referenceable = (bool) _nodereference_potential_references_views($field, '', NULL, array($node->nid), 1);
-  }
-  // Otherwise restrict by node type.
-  else {
-    $referenceable = !empty($field['referenceable_types'][$node->type]);
+  if (module_exists('views') && isset($field['advanced_view']) && !empty($field['advanced_view']) && $field['advanced_view'] != '--') {
+    $referenceable = (bool) _node_reference_potential_references($field, '', NULL, array($node->nid), 1);
+  } else {
+    $field_info = field_info_field($field['field_name']);
+    $referenceable = !empty($field_info['settings']['referenceable_types'][$node->type]);
   }
 
-  if ($referenceable && node_access('create', $field['type_name'])) {
-    $link_settings = $field['widget']['node_link'];
-    if ((!empty($link_settings['teaser']) && $teaser == TRUE) || (!empty($link_settings['full']) && $teaser == FALSE)) {
+  if ($referenceable && node_access('create', $field['bundle'])) {
+    $link_settings = $field['widget']['settings']['node_link'];
+    if ( !empty($link_settings[$view_mode]) ) {
       // Get the first "preferred" path for creating Node Reference links.
       $link_urls = variable_get('nodereference_url_paths', array('node/add/%type/%nid'));
 
       // Basic wildcard replacement: %type and %nid.
       $link_url = $link_urls[0];
-      $link_url = str_replace('%type', str_replace('_', '-', $field['type_name']), $link_url);
+      $link_url = str_replace('%type', str_replace('_', '-', $field['bundle']), $link_url);
       $link_url = str_replace('%nid', $node->nid, $link_url);
 
       $link = array(
@@ -131,10 +129,10 @@ function nodereference_url_build_link($node, $field, $teaser = FALSE) {
       }
       if (!empty($link_settings['destination'])) {
         if ($link_settings['destination'] == 'source') {
-          $link['query'] = drupal_get_destination();
+          $link['query'] = array ( 'destination' => drupal_get_destination());
         }
         elseif ($link_settings['destination'] == 'node') {
-          $link['query'] = 'destination='. urlencode(drupal_get_path_alias('node/'. $node->nid));
+          $link['query'] = array ('destination' => drupal_get_path_alias('node/'. $node->nid));
         }
       }
       if (module_exists('og')) {
@@ -147,8 +145,7 @@ function nodereference_url_build_link($node, $field, $teaser = FALSE) {
         }
 
         if ($group_node) {
-          $link['query'] = isset($link['query']) ? $link['query'] . '&' : '';
-          $link['query'] .= 'gids[]=' . $group_node->nid;
+        $link['query']['gids'] = $group_node->nid;
         }
       }
     }
@@ -158,157 +155,88 @@ function nodereference_url_build_link($node, $field, $teaser = FALSE) {
 }
 
 /**
- * Helper function for themers to easily create a link.
- *
- * This function should be used in custom themes, rather than making manual
- * links because it first checks a user's access before showing the link. If
- * the user does not have access to create the node then an empty string will
- * be returned.
- *
- * @param $node
- *   The node object that will be referenced.
- * @param $field_name
- *   The name of the Node Reference field.
- * @param $type_name
- *   The name of node type that contains the Node Reference field.
- * @param $attributes
- *   Optional. An array of additional attributes to add to the link.
- */
-function nodereference_url_create_link($node, $field_name, $type_name, $attributes = array()) {
-  $output = '';
-  $field = content_fields($field_name, $type_name);
-  $field['widget']['node_link']['full'] = TRUE;
-  if ($link = nodereference_url_build_link($node, $field)) {
-    $options = array();
-    $options['attributes'] = $attributes + (array) $link['attributes'];
-    if ($link['query']) {
-      $options['query'] = $link['query'];
-    }
-    $output = l($link['title'], $link['href'], $options);
-  }
-  return $output;
-}
-
-/**
- * Helper function to retrieve all instances of a field.
- */
-function _nodereference_url_field_instances($field_name) {
-  $info = _content_type_info();
-  $instances = array();
-  foreach (node_get_types('names') as $node_type => $node_type_name) {
-    if (isset($info['content types'][$node_type]['fields'][$field_name])) {
-      $instances[$node_type] = $info['content types'][$node_type]['fields'][$field_name];
-    }
-  }
-  return $instances;
-}
-
-/**
- * Implementation of FAPI hook_elements().
- *
- * Any FAPI callbacks needed for individual widgets can be declared here,
- * and the element will be passed to those callbacks for processing.
- *
- * Drupal will automatically theme the element using a theme with
- * the same name as the hook_elements key.
- *
- * Autocomplete_path is not used by text_widget but other widgets can use it
- * (see nodereference and userreference).
- */
-function nodereference_url_elements() {
-  return array(
-    'nodereference_url' => array(
-      '#input' => TRUE,
-      '#columns' => array('nid'),
-      '#delta' => 0,
-      '#process' => array('nodereference_url_process'),
-    ),
-  );
-}
-
-/**
- * Implementation of hook_widget_settings().
+ * Implements of hook_field_widget_settings_form().
  */
-function nodereference_url_widget_settings($op, $widget) {
-  switch ($op) {
-    case 'form':
-      $form = array();
-      if ($widget['type'] == 'nodereference_url') {
-        $form['fallback'] = array(
+function nodereference_url_field_widget_settings_form($field, $instance) {
+  $widget   = $instance['widget'];
+  $defaults = field_info_widget_settings($widget['type']);
+  $settings = array_merge($defaults, $widget['settings']);
+
+  $form = array();
+  if ($widget['type'] == 'nodereference_url') {
+    $form['fallback'] = array(
           '#type' => 'radios',
           '#title' => t('Fallback behavior'),
           '#options' => array(
-            'autocomplete' => t('Use autocomplete widget'),
-            'select' => t('Use select list widget'),
             'page_not_found' => t('Display page not found error'),
+            'select' => t('Use select list widget'),
+            'autocomplete' => t('Use autocomplete widget'),
             'leave_blank' => t('Leave the field blank'),
-          ),
-          '#default_value' => isset($widget['fallback']) ? $widget['fallback'] : 'autocomplete',
+    ),
+          '#default_value' => isset($settings['fallback']) ? $settings['fallback'] : 'page_not_found',
           '#description' => t('If no content is referenced in the URL, determine how the form should be handled.'),
           '#required' => TRUE,
           '#element_validate' => array('nodereference_url_fallback_validate'),
-          '#weight' => -3,
-        );
-        $form['edit_fallback'] = array(
-          '#type' => 'checkbox',
-          '#title' => t('Use fallback behavior when editing content'),
-          '#default_value' => isset($widget['edit_fallback']) ? $widget['edit_fallback'] : FALSE,
-          '#weight' => -2,
-        );
-
-        $form['node_link'] = array(
+    );
+
+    $form['node_link'] = array(
           '#tree' => TRUE,
           '#type' => 'fieldset',
           '#title' => t('Referenceable node links'),
           '#element_validate' => array('nodereference_url_node_link_validate'),
           '#description' => t('These settings will automatically make a link on nodes that can be referenced. Clicking the link will take the user to the new node form and prepopulate the value of this node reference field.'),
-        );
-        $form['node_link']['teaser'] = array(
-          '#type' => 'checkbox',
-          '#title' => t('Create link on the teaser view'),
-          '#default_value' => isset($widget['node_link']['teaser']) ? $widget['node_link']['teaser'] : FALSE,
-        );
-        $form['node_link']['full'] = array(
-          '#type' => 'checkbox',
-          '#title' => t('Create link on the full view'),
-          '#default_value' => isset($widget['node_link']['full']) ? $widget['node_link']['full'] : TRUE,
-        );
-        $form['node_link']['title'] = array(
+    );
+    $form['node_link']['teaser'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Create link on the teaser view'),
+      '#default_value' => isset($settings['node_link']['teaser']) ? $settings['node_link']['teaser'] : FALSE,
+    );
+    $form['node_link']['full'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Create link on the full view'),
+      '#default_value' => isset($settings['node_link']['full']) ? $settings['node_link']['full'] : TRUE,
+    );
+    $form['node_link']['title'] = array(
           '#type' => 'textfield',
           '#title' => t('Link title'),
-          '#default_value' => isset($widget['node_link']['title']) ? $widget['node_link']['title'] : '',
+          '#default_value' => isset($settings['node_link']['title']) ? $settings['node_link']['title'] : '',
           '#description' => t('The title is the visible text for the link. This is required if you enable the content links.'),
-        );
-        $form['node_link']['hover_title'] = array(
+          '#required' => TRUE,
+    );
+    $form['node_link']['hover_title'] = array(
           '#type' => 'textfield',
           '#title' => t('Link hover title'),
-          '#default_value' => isset($widget['node_link']['hover_title']) ? $widget['node_link']['hover_title'] : '',
+          '#default_value' => isset($settings['node_link']['hover_title']) ? $settings['node_link']['hover_title'] : '',
           '#description' => t('Text shown while hovering over the link.'),
-        );
-        $form['node_link']['destination'] = array(
+    );
+    $form['node_link']['destination'] = array(
           '#type' => 'select',
           '#title' => t('Return path'),
-          '#default_value' => isset($widget['node_link']['destination']) ? $widget['node_link']['destination'] : 'default',
+          '#default_value' => isset($settings['node_link']['destination']) ? $settings['node_link']['destination'] : 'default',
           '#options' => array(
             'default' => t('The new node (no redirect)'),
             'node' => t('The referenced node'),
             'source' => t('The previous page'),
-          ),
+    ),
           '#description' => t('After creating the new node through the link, determine where the user should be redirected.'),
-        );
-      }
-      return $form;
+    );
+   }
+  return $form;
+}
 
-    case 'save':
-      return array('node_link', 'fallback', 'edit_fallback');
-  }
+
+/**
+ * Implements hook_field_widget_error().
+ */
+function nodereference_url_field_widget_error($element, $error, $form, &$form_state) {
+  form_error($element['nid'], $error['message']);
 }
 
 /**
  * Element validation function to ensure invalid options are not selected.
  */
 function nodereference_url_fallback_validate($element, &$form_state) {
-  if ($form_state['values']['required'] && $form_state['values']['fallback'] == 'leave_blank') {
+  if ($form_state['values']['instance']['required'] && $form_state['values']['instance']['widget']['settings']['fallback'] == 'leave_blank') {
     form_error($element, t('The fallback behavior cannot be left blank if this field is also required.'));
   }
 }
@@ -319,32 +247,32 @@ function nodereference_url_fallback_validate($element, &$form_state) {
  * This function doesn't actually validate, it just reformats form_state value
  * into an array of a suitable format for nodereference module
  */
-function nodereference_url_autocomplete_validate($element, &$form_state) {
+function nodereference_url_autocomplete_validate($element, &$form_state, $form) {
   form_set_value($element, array($form_state['values'][$element['#field_name']]), $form_state);
 }
 
 /**
  * Element validation function that makes title required when creating a link.
  */
-function nodereference_url_node_link_validate($element, &$form_state) {
-  $link_settings = $form_state['values']['node_link'];
+function nodereference_url_node_link_validate($element, &$form_state, $form) {
+  $link_settings = $form_state['values']['instance']['widget']['settings']['node_link'];
   if (($link_settings['teaser'] || $link_settings['full']) && empty($link_settings['title'])) {
     form_error($element['title'], t('A link title must be specified if creating links on referenceable content.'));
   }
 }
 
 /**
- * Implementation of hook_widget().
+ * Implements of hook_field_widget_form().
  */
-function nodereference_url_widget(&$form, &$form_state, $field, $items, $delta = 0) {
-  $element = array('#tree' => TRUE);
+function nodereference_url_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
+  $fallback = $instance['widget']['settings']['fallback'];
   $field_name = $field['field_name'];
   $field_name_url = preg_replace('/^field_/', '', $field_name);
   $referenced_nid = NULL;
 
   // Check for an existing NID.
-  if (isset($items[0]['nid']) && is_numeric($items[0]['nid'])) {
-    $referenced_nid = $items[0]['nid'];
+  if (isset($items[$delta]['nid']) && is_numeric($items[$delta]['nid'])) {
+    $referenced_nid = $items[$delta]['nid'];
   }
   // Check for a reference in the query string.
   elseif (isset($_GET[$field_name_url]) && is_numeric($_GET[$field_name_url])) {
@@ -357,101 +285,64 @@ function nodereference_url_widget(&$form, &$form_state, $field, $items, $delta =
 
   // Check that the NID is a valid reference.
   if (!empty($referenced_nid)) {
-    $reference = _nodereference_potential_references($field, '', 'equals', array($referenced_nid), 1);
+    $reference = _node_reference_potential_references($field, '', 'equals', array($referenced_nid), 1);
     if (empty($reference)) {
       $referenced_nid = NULL;
+    } else {
+      $reference_title = $reference[$referenced_nid]['title'];
     }
   }
 
   // If no NID is available or editing this field, use the fallback behavior.
-  if (empty($referenced_nid) || (!empty($field['widget']['edit_fallback']) && !empty($items))) {
+  if (empty($referenced_nid) || (!empty($field['widget']['edit_fallback']) && !empty($items[$delta]['nid']))) {
+
     // If not on a node/add page (such as editing a node that does not yet have
     // a reference), switch to using an autocomplete widget.
-    if (in_array($field['widget']['fallback'], array('page_not_found', 'leave_blank')) && nodereference_url_get_nid($field_name) === FALSE) {
-      $field['widget']['fallback'] = 'autocomplete';
+    if (in_array($fallback, array('page_not_found', 'leave_blank')) && nodereference_url_get_nid($field_name) === FALSE) {
+      $fallback = 'autocomplete';
     }
 
     // Page not found error.
     // Check for the form_build_id to prevent throwing a page not found on
     // manual builds. See http://drupal.org/node/397606.
-    if ($field['widget']['fallback'] == 'page_not_found' && isset($form['form_build_id'])) {
-      drupal_set_message(t('To create a new @type, a referenced piece of content must be specified in the link you followed.', array('@type' => node_get_types('name', $field['type_name']))), 'error');
+    if ($fallback == 'page_not_found') {
+      drupal_set_message(t('To create a new @type, a referenced piece of content must be specified in the link you followed.', array('@type' => $field['bundles']['node'][0])), 'error');
       drupal_not_found();
       exit();
     }
     // Fallback to select list.
-    elseif ($field['widget']['fallback'] == 'select') {
-      $element = array(
-        '#type' => 'nodereference_select',
-        '#default_value' => $items,
-        '#after_build' => array('nodereference_url_process_select'),
+    elseif ($fallback == 'select' || $fallback == '') {
+      $element += array(
+        '#type' => 'select',
+        '#default_value' => isset($items[$delta]['nid']) ? $items[$delta]['nid'] : NULL,
+        '#options' => array('' => t('- None -')) + node_reference_options_list($field),
       );
     }
     // Fallback to autocomplete.
-    elseif ($field['widget']['fallback'] == 'autocomplete') {
-      $element = array(
-        '#type' => 'nodereference_autocomplete',
-        '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
-        '#value_callback' => 'nodereference_autocomplete_value',
-        '#element_validate' => array('nodereference_url_autocomplete_validate'),
+    elseif ($fallback == 'autocomplete') {
+      $element += array(
+        '#type' => 'textfield',
+        '#default_value' => isset($items[$delta]['nid']) ? $items[$delta]['nid'] : NULL,
+        '#autocomplete_path' => 'node_reference/autocomplete/' . $instance['entity_type'] . '/' . $field['field_name'],
+        '#value_callback' => 'node_reference_autocomplete_value',
+        '#element_validate' => array('node_reference_autocomplete_validate'),
       );
     }
   }
 
   if (isset($referenced_nid) && (empty($element['#type']))) {
-    $element[0]['nid'] = array(
-      '#title' => $field['widget']['label'],
-      '#type' => 'nodereference_url',
-      '#field_name' => $field_name,
-      '#default_value' => $referenced_nid,
+    $element += array(
+      '#type' => 'value',
+      '#value' => $referenced_nid,
+    );
+    $element['referenced_title'] = array(
+      '#type' => 'item',
+      '#title' => $instance['label'],
+      '#markup' => '<span class="' . $field_name . '">' . $reference_title . '</span>',
     );
   }
 
-  return $element;
-}
-
-/**
- * Process an individual element.
- *
- * Build the form element. When creating a form using FAPI #process,
- * note that $element['#value'] is already set.
- *
- * The $fields array is in $form['#field_info'][$element['#field_name']].
- */
-function nodereference_url_process($element, $edit, $form_state, $form) {
-  $field_key = $element['#columns'][0];
-  $field = $form['#field_info'][$element['#field_name']];
-
-  if (isset($element['#value']) && is_numeric($element['#value'])) {
-    $element['#display_title'] = _nodereference_titles($element['#value']);
-  }
-  else {
-    $element['#display_title'] = t('Referenced content not found.');
-  }
-
-  $element['nid'] = array(
-    '#type' => 'value',
-    '#value' => isset($element['#value']) ? $element['#value'] : $element['#value'],
-    '#parents' => $element['#parents'],
-  );
-
-  return $element;
-}
-
-/**
- * An #after_build function used to add an empty value to the list of options.
- *
- * Normally CCK would do this in optionwidgets_options(), but since the widget
- * type "nodereference_url" isn't known by it, we have to add it manually.
- */
-function nodereference_url_process_select($element, $form_state) {
-  if (isset($element['nid']['nid']['#options'])) {
-    $field = content_fields($element['#field_name'], $element['#type_name']);
-    $field['widget']['type'] = 'optionwidgets_select';
-    $element['nid']['nid']['#options'] = array('' => theme('optionwidgets_none', $field)) + $element['nid']['nid']['#options'];
-  }
-
-  return $element;
+  return array('nid' => $element);
 }
 
 /**
@@ -494,6 +385,96 @@ function nodereference_url_get_nid($field_name) {
 }
 
 /**
+ * Helper function for themers to easily create a link.
+ *
+ * This function should be used in custom themes, rather than making manual
+ * links because it first checks a user's access before showing the link. If
+ * the user does not have access to create the node then an empty string will
+ * be returned.
+ *
+ * @param $node
+ *   The node object that will be referenced.
+ * @param $field_name
+ *   The name of the Node Reference field.
+ * @param $type_name
+ *   The name of node type that contains the Node Reference field.
+ * @param $attributes
+ *   Optional. An array of additional attributes to add to the link.
+ */
+function nodereference_url_create_link($node, $field_name, $type_name, $attributes = array()) {
+  $output = '';
+  $field = content_fields($field_name, $type_name);
+  $field['widget']['node_link']['full'] = TRUE;
+  if ($link = nodereference_url_build_link($node, $field)) {
+    $options = array();
+    $options['attributes'] = $attributes + (array) $link['attributes'];
+    if ($link['query']) {
+      $options['query'] = $link['query'];
+    }
+    $output = l($link['title'], $link['href'], $options);
+  }
+  return $output;
+}
+
+/**
+ * Implementation of FAPI hook_elements().
+ *
+ * Any FAPI callbacks needed for individual widgets can be declared here,
+ * and the element will be passed to those callbacks for processing.
+ *
+ * Drupal will automatically theme the element using a theme with
+ * the same name as the hook_elements key.
+ *
+ * Autocomplete_path is not used by text_widget but other widgets can use it
+ * (see nodereference and userreference).
+ */
+function nodereference_url_element_info() {
+  return array(
+    'nodereference_url' => array(
+      '#input' => TRUE,
+      '#columns' => array('nid'),
+      '#delta' => 0,
+      '#process' => array('nodereference_url_process'),
+    ),
+  );
+}
+
+/**
+ * Process an individual element.
+ *
+ * Build the form element. When creating a form using FAPI #process,
+ * note that $element['#value'] is already set.
+ *
+ * The $fields array is in $form['#field_info'][$element['#field_name']].
+ */
+function nodereference_url_process($form, $type) {
+  if ($type == 'field') {
+    if ( isset($form['field_type']) && $form['field_type'] == 'node_reference') {
+      $field_key = $form['field_name'];
+      $element = $form['element'];
+      $field=$form['object']->$field_key;
+      if (isset($element['#items'][0]['nid']) && is_numeric($element['#items'][0]['nid'])) {
+        $element['#title'] = _node_reference_get_node_titles(array($element['#items'][0]['nid']));
+     } else {
+        $element['#title'] = t('Referenced content not found.');
+      }     
+    }
+   }
+  return $form;
+}
+
+/**
+ * Implements of hook_theme().
+ */
+function nodereference_url_theme() {
+  return array(
+    'nodereference_url' => array(
+      'arguments' => array('element' => NULL),
+    ),
+  );
+}
+
+/**
  * FAPI theme for an individual elements.
  *
  * The textfield or select is already rendered by the
