--- noderefcreate.module	2009-07-03 04:21:23.000000000 -0400
+++ noderefcreateNew.module	2010-08-11 15:59:28.000000000 -0400
@@ -1,5 +1,67 @@
 <?php 
 
+/**
+ * Implementation of hook_menu().
+ */
+function noderefcreate_menu() {
+  $items['admin/settings/noderefcreate'] = array(
+    'title' => 'Nodereference creation',
+    'description' => 'Settings for node reference creation.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('noderefcreate_settings'),
+    'access arguments' => array('administer site configuration'),
+  );
+  $items['noderefcreate/autocomplete'] = array(
+    'title' => 'Noderefcreate autocomplete',
+    'page callback' => 'noderefcreate_autocomplete',
+    'access callback' => 'nodereference_autocomplete_access',
+    'access arguments' => array(2), 
+    'type' => MENU_CALLBACK
+  );
+  return $items;
+}
+
+/**
+ * Form for configuring node reference creation settings.
+ *
+ * @see system_settings_form()
+ */
+function noderefcreate_settings() {
+
+  $form['noderefcreate_show_nid'] = array(
+    '#type' => 'radios',
+    '#title' => t('For autocomplete node references using node reference create'),
+    '#default_value' => variable_get('noderefcreate_show_nid', 1),
+    '#options' => array(t('Hide node ids from display (see notes below)'), t('Show node ids')),
+    '#description' => t('Hiding the node ids may make your site more usable, but be warned that if two or more nodes of the selected types share the same node title, the resulting choice will be arbitrary.'),
+  );
+
+  return system_settings_form($form);
+}
+
+/**
+ * Menu callback; Retrieve a pipe delimited string of autocomplete suggestions for existing users.
+ * Overrides nodereference_autocomplete to omit the "[nid:xxx]" if setting dictates.
+ */
+function noderefcreate_autocomplete($field_name, $string = '') {
+  $fields = content_fields();
+  $field = $fields[$field_name];
+  $match = isset($field['widget']['autocomplete_match']) ? $field['widget']['autocomplete_match'] : 'contains';
+  $matches = array();
+
+  $references = _nodereference_potential_references($field, $string, $match, array(), 10);
+  foreach ($references as $id => $row) {
+    // Add a class wrapper for a few required CSS overrides.
+    if (variable_get('noderefcreate_show_nid', 1)) {
+      $matches[$row['title'] ." [nid:$id]"] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>';
+    }
+    else {
+      $matches[$row['title']] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>';
+    }
+  }
+  drupal_json($matches);
+}
+
 function noderefcreate_widget_info() {
   return array(
     'noderefcreate_autocomplete' => array(
@@ -47,7 +109,7 @@ function noderefcreate_widget(&$form, &$
       $element = array(
         '#type' => 'nodereference_autocomplete',
         '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
-        '#value_callback' => 'nodereference_autocomplete_value',
+        '#value_callback' => 'noderefcreate_autocomplete_value',
       	'#process' => array('noderefcreate_autocomplete_process'),
       );
       break;
@@ -55,6 +117,24 @@ function noderefcreate_widget(&$form, &$
   return $element;
 }
 
+/**
+ * Value for a noderefcreate autocomplete element. Overrides nodereference_autocomplete to omit
+ * the "[nid:xxx]" from appearing in form element if setting applied.
+ *
+ * Substitute in the node title for the node nid.
+ */
+function noderefcreate_autocomplete_value($element, $edit = FALSE) {
+  $field_key  = $element['#columns'][0];
+  if (!empty($element['#default_value'][$field_key])) {
+    $nid = $element['#default_value'][$field_key];
+    $value = db_result(db_query(db_rewrite_sql('SELECT n.title FROM {node} n WHERE n.nid = %d'), $nid));
+    if (variable_get('noderefcreate_show_nid', 1)) {
+      $value .= ' [nid:'. $nid .']';
+    }
+    return array($field_key => $value);
+  }
+  return array($field_key => NULL);
+}
 
 function noderefcreate_autocomplete_process($element, $edit, $form_state, $form) {
 
@@ -67,7 +147,7 @@ function noderefcreate_autocomplete_proc
   $element[$field_key] = array(
     '#type' => 'text_textfield',
     '#default_value' => isset($element['#value']) ? $element['#value'] : '',
-    '#autocomplete_path' => 'nodereference/autocomplete/'. $element['#field_name'],
+    '#autocomplete_path' => 'noderefcreate/autocomplete/'. $element['#field_name'],
     // The following values were set by the content module and need
     // to be passed down to the nested element.
     '#title' => $element['#title'],
