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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jrockowitz’s picture

Status: Needs review » Reviewed & tested by the community

I 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

svendecabooter’s picture

Any 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')

Cyberwolf’s picture

Subscribing.

dww’s picture

Re-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

pwolanin’s picture

Status: Reviewed & tested by the community » Fixed

committed to 6 and 7. Thanks.

dww’s picture

Yay, thanks for the speedy commit and push. ;)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 0dfdfd1 on 7.x-1.x, 8.x-1.x authored by dww, committed by pwolanin:
    Bug #939016 by svendecabooter, dww: Cloned node ID not set via...