--- fieldactions.module.orig	2010-08-13 17:33:52.000000000 -0700
+++ fieldactions.module	2010-08-13 19:35:38.000000000 -0700
@@ -27,6 +27,14 @@
         'nodeapi' => array('insert', 'update')
       )
     ),
+    'fieldactions_nodereference_from_parent_node_action' => array(
+      'description' => t('Reference from another node'),
+      'configurable' => TRUE,
+      'type' => 'node',
+      'hooks' => array(
+        'nodeapi' => array('insert', 'update')
+      )
+    ),
     'fieldactions_send_email_to_userreference_action' => array(
       'description' => t('Send email to a user reference field'),
       'type' => 'node',
@@ -189,6 +197,90 @@
 }
 
 /**
+ * Implementation of an action.
+ * Adds a node reference from the parent node to the selected node.
+ */
+function fieldactions_nodereference_from_parent_node_action($node, $context) {
+
+  // Always load the parent node fresh, since this action could be called
+  // multiple times.
+  $parent_node = node_load($context['nr_parent_nid'], NULL, TRUE);
+
+  // Make sure the node we're adding the reference for isn't already referenced
+  // from the parent node.
+  $already_referenced = FALSE;
+  foreach($parent_node->{$context['nr_parent_field_name']} as $parent){
+    if($parent['nid'] == $node->nid){
+      $already_referenced = TRUE;
+      break;
+    }
+  }
+
+  if ($already_referenced){
+    drupal_set_message(t('%child_node is already referenced by %parent_node.', array('%child_node' => $node->title, '%parent_node' => $parent_node->title)), 'error');
+  }
+  else {
+    $parent_node->{$context['nr_parent_field_name']}[]['nid'] = $node->nid;
+    node_save($parent_node);
+  }
+}
+
+/**
+ * Form array for configuring the advanced action to add a nodereference from
+ * a parent node.
+ */
+function fieldactions_nodereference_from_parent_node_action_form($context) {
+  $form = array();
+  $form['nr_parent_nid'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Node ID of the parent node'),
+    '#size' => 10,
+    '#default_value' => !empty($context['nr_parent_nid']) ? $context['nr_parent_nid'] : '',
+    '#description' => t('Enter the node ID of the node that will be parent for this reference.'),
+    '#required' => TRUE,
+  );
+  $form['nr_parent_field_name'] = array(
+    '#type' => 'select',
+    '#title' => t('Parent node reference field'),
+    '#default_value' => !empty($context['nr_parent_field_name']) ? $context['nr_parent_field_name'] : '',
+    '#options' => _fieldactions_nodereference_fields(),
+    '#description' => t('Select the node reference field in the parent node that you wish to use to place a reference for this node.'),
+    '#required' => TRUE,
+  );
+
+  return $form;
+}
+
+/**
+ * Form validation for adding a nodereference from a parent node.
+ */
+function fieldactions_nodereference_from_parent_node_action_validate($form, &$form_state) {
+  if (!is_numeric($form_state['values']['nr_parent_nid'])) {
+    form_set_error('nr_parent_nid', t('The parent node ID value must be numeric.'));
+  }
+  elseif ($node = node_load($form_state['values']['nr_parent_nid'])) {
+    // Verify that the selected nodereference field actually exists in the
+    // parent node.
+    if (!isset($node->{$form_state['values']['nr_parent_field_name']})) {
+      form_set_error('nr_parent_field_name', t('Field %field does not exist in parent node %title.', array('%field' => $form_state['values']['nr_parent_field_name'], '%title' => $node->title)));
+    }
+  }
+  else {
+    form_set_error('nr_parent_nid', t('Specified parent node does not exist.'));
+  }
+}
+
+/**
+ * Form submission for adding a nodereference from a parent node.
+ */
+function fieldactions_nodereference_from_parent_node_action_submit($form, &$form_state) {
+  return array(
+    'nr_parent_field_name' => $form_state['values']['nr_parent_field_name'],
+    'nr_parent_nid' => $form_state['values']['nr_parent_nid']
+  );
+}
+
+/**
  * Implementation of a Drupal action.
  * This action sends email to each user in a user reference field.
  * If the field is empty, no email will be sent.
@@ -552,15 +644,20 @@
  */
 function _fieldactions_nodereference_fields() {
   $allfields = content_fields();
+  $node_types = node_get_types('names');
   $fields = array();
   foreach ($allfields as $name => $field) {
     if ($field['type'] == 'nodereference') {
+      $content_type_label = $node_types[$field['type_name']];
+      $widget_label = $field['widget']['label'];
       // if a field is used twice, we only need one label, but we append
-      // the field name to remove ambiguity about where this will apply
-      $fields[$name] = $field['widget']['label'] ." ($name)";
+      // the field name to remove ambiguity about where this will apply.
+      $fields[$name] = "$content_type_label: $widget_label ($name)";
     }
   }
 
+  natcasesort($fields);
+
   return $fields;
 }
 
