From a587ebb01cfa8581ea1d12d170e0a57e8aa0a00d Mon Sep 17 00:00:00 2001
From: Derek Wright <git@dwwright.net>
Date: Thu, 30 Jun 2011 19:35:37 -0500
Subject: [PATCH] Bug #939016 by svendecabooter, dww: Cloned node ID not set via prepopulate.

This functionality was never finished at #654508. Previously, the only
way to know you were inserting a cloned node was if clone.module was
configured to use save-edit, not prepopulate. Now, we use
hook_form_alter() to inject a 'value' form element into the node form
so that $node->clone_from_original_nid is propagated all the way
through node_save() and friends to reach nodeapi('insert').
---
 clone.module |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/clone.module b/clone.module
index 74393e5..f95cf2a 100644
--- a/clone.module
+++ b/clone.module
@@ -114,3 +114,19 @@ function clone_init() {
   }
 }
 
+/**
+ * Implementation of hook_form_alter().
+ */
+function clone_form_alter(&$form, $form_state, $form_id) {
+  // Add the clone_from_original_nid value for node forms triggered by cloning.
+  // This will make sure the clone_from_original_nid property is still
+  // attached to the node when passing through hook_nodeapi($op = insert).
+  if (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id) {
+    if (!empty($form['#node']->clone_from_original_nid)) {
+      $form['clone_from_original_nid'] = array(
+        '#type' => 'value',
+        '#value' => $form['#node']->clone_from_original_nid,
+      );
+    }
+  }
+}
-- 
1.7.3.5

