Hi,
I use the functionality to determine of a node was cloned (provided through issue #654508: Add a way to determinee that a node was a clone) in my module webform_validation, to allow this module to copy webform validation rules to newly cloned nodes.
This works perfectly when the Clone module cloning settings are set to save-edit ("Save as a new node then edit"):
The $node->clone_from_original_nid property gets filled and then passed on through node_save.
My module checks for the existence of this property after the node has been saved in hook_nodeapi - op "insert".
This works as advertised.
However when the cloning settings are set to prepopulate ("Pre-populate the node form fields"), the patch in #654508: Add a way to determinee that a node was a clone also adds the $node->clone_from_original_nid property, but since there is no form element, this value gets lost after the form is submitted, so it's no longer available in hook_nodeapi during the "insert" op.
Attached is a patch that makes this behaviour more consistent. The clone_from_original_nid value is now available in hook_nodeapi - op "insert", regardless of the selected cloning method.
Comment | File | Size | Author |
---|---|---|---|
#4 | 939016-4.node-clone-prepopulate-remember-nid.patch | 1.52 KB | dww |
clone_from_original_nid_form_element.patch | 1.02 KB | svendecabooter |
Comments
Comment #1
jrockowitz CreditAttribution: jrockowitz commentedI just tested this patch against node clone 6.x-1.2 and can confirm that it works fine.
I changed this issue's status to RTBC because the code and solution is pretty straight forward and concise.
Thanks,
~ jake
Comment #2
svendecabooterAny input on this?
I need this to get Webform Validation module working nicely with Node Clone (see #911632: Validation rules not being clone if clone module is set to 'pre-populate the node form fields')
Comment #3
Cyberwolf CreditAttribution: Cyberwolf commentedSubscribing.
Comment #4
dwwRe-rolled this patch for a few reasons:
A) #type 'value' is better for this than 'hidden' since it can't be tampered with via POST treachery.
B) Used !empty() to avoid possible PHP notices when checking if
$form['#node']->clone_from_original_nid
is defined.C) Code style: comments weren't wrapped to 80 chars.
Tested heavily on both 6.x-1.x and 7.x-1.x branches (which also required the latest from #986242: Drupal 7 fixes.).
I also took the liberty of writing a sane commit message and attaching it here via git format-patch. ;) (Obviously feel free to edit as needed).
Anyway, even though it's my own patch, I'm going to leave this at RTBC since I know it's ready.
I'd love to see this committed ASAP since #1205304: Clone the panels display if using node_clone to clone a panelized node is now done but will only work consistently once this patch is in.
Thanks!
-Derek
Comment #5
pwolanin CreditAttribution: pwolanin commentedcommitted to 6 and 7. Thanks.
Comment #6
dwwYay, thanks for the speedy commit and push. ;)