Hello, I am new to Drupal and trying to learn. I apoligize if I have posted this in the wrong place, since this is my first post. If its wrong, can someone tell me where to post this type of thing in the future.
Project: Node Clone
Problem: I need to make a slight modification that will perform the following: I am using "prepopulated" forms and "Require Confirmation". Upon submission of the "Cloned node" I need to unpublish the old node. So far I have written the following code, but just cannot figure out where to stick it to make sure it executes after someone clicks "SAVE" on the "Clone of Content" form.
code:
db_update('node')
->fields(array( 'status' => 0))
->condition('nid', $original_node->nid, "=")
->execute();
I originally wrote the code within the function clone_node_prepoulate($original_node) on the clone.pages.inc hence the variable $original_node->nid. However, if I leave it within this function, then the code executes automatically even if the user clicks "Clone Content" link and then decides not to actual save the new "Clone of Content" form. If they just close out, it still executes my code and sets publish status to 0.
So, if you know where I can stick this code or if the code is inappropriate and I should have written something else, then any direction is much appreciated.
Thanks again
J.
Any ideas where to
Comments
Comment #1
enkara commentedI don't know why do you need this, but do you know revisions? Maybe is what you need
Comment #2
Wallace123455 commentedEnkara, thanks for the reply. To provide a little more background:
I need this feature because I need to old node to remain in an "Archived" state. My thought was once the individual clicks clone content and saves the clone content, then I can change the status of the old node to 0 = Unpublished. Therefore the old node would still exist and would now not be published.
I have created views already so my users can only see published nodes, so essentially, the user will be looking at the "new node" although in effect, they will think they have just "editted" their original node.
I have some requirements in my industry for which I am developing my drupal project which require a complete history of all nodes (cannot be changed once created). So basically I am just trying to figure out a way to upon completion of the clone content screen the old node will go from published to unpublished automatically.
My original attempt at codes is just a direct database modification to the status of the old node. The code works, I just need to figure out how to implement so it happens after an individual clicks "Save clone content form". I obviously do not want the unpublishing to happen if the individual opens a "clone content" but decides not not actual save anything (e.g. cancelling).
If you or anyone has any good ideas of how to implement this, please let me know.
Comment #3
enkara commentedHi Wallace123455,
If you think the best way to achieve your requirements is this, the easiest way to execute a code after a node is saved is using the module Rules. What I don't know is if you can check in any way if the saved node is a clone of another. Take a look to the module and investigate.
You could also create a new module and use hooks, but I think it's more complex and as you are new to drupal, Rules will work ok for you.
But I really think that the perfect thing for you is Revisions. Revisions do exactly what you need. The only problem is that you need the revisions to be mandatory. Doing a quick search: http://drupal.org/node/249677
Hope it helps!
Comment #4
johnvHi Wallace, have you accomplished your goals?
If you'd like to re-open this issue, please make the title more descriptive.