I have a use case where I have an array of date fields on a node (from date repeat in Date API) and I need to add a button on the node edit form to convert each entry in the array to a new, identical node with a single date entry.
I looked at a few other modules that claim to implement what I'm trying to achieve such as http://drupal.org/project/date_repeat_nodegen and http://drupal.org/project/node_repeat but they all seem to be poorly maintained and there's a lot of outstanding issues around nodes not being cloned "cleanly".
I've used node_clone before in a few different projects and I think it does the job of duplicating a node quite well.
What I wanted to do was simply create a function that fires on submit that loops through the date array from my original node and calls clone_node_save() with a corresponding hook_clone_node_alter() function to make sure the date information on the new node is correct.
The problem is that right now all I have access to in hook_clone_node_alter() is the original node object, the new node object and whether we're in save-edit or prepopulate mode.
The extra bit of information that I'm looking for is of course a counter or similar so I know where I'm up to in my loop and can add the correct date to the new node. Adding an optional variable that could be passed to clone_node_save to hold external paramaters and passing that to the hook function should be enough to get what I want.
I figured that worst-case I could pop dates off my original node as the new nodes are being created but this doesn't feel like it would be the "best" way to go about this.
Comment | File | Size | Author |
---|---|---|---|
#1 | 1515866-optional-params-for-node_clone_save.patch | 2.19 KB | thedavidmeister |
Comments
Comment #1
thedavidmeister CreditAttribution: thedavidmeister commentedPatch attached.
I included an extra params variable for clone_node_prepopulate as well to ensure a consistent interface when implementing hook_clone_node_alter.
Comment #2
thedavidmeister CreditAttribution: thedavidmeister commentedComment #2.0
thedavidmeister CreditAttribution: thedavidmeister commentedadding extra contextual information to my use-case
Comment #3
pwolanin CreditAttribution: pwolanin commentedI guess I can see this being marginally useful, though there are a number of other ways you could achieve the same end goal.
I don't really think it's a feature I want to add to 6.x at this point.