By jniesen on
Hi
The content types we're using allow the editor to attach taxonomy to the content.
I need to create functionality when a user is editing a node that will:
1. Check to see if the taxonomy attached to the content has changed
2. If it has, create new content instead of editing the current.
I know you can override form functions, but I'm lost on which one/ how to do this if I should be using hook_form_submit, or some other hook. Any advice is appreciated.
Thanks
James
Comments
please explain
I don't understand what you mean with "see if the taxonomy attached to the content has changed". Do you mean that the taxonomy term object has changed (eg. the term name or description)? Or do you mean that the terms assigned to the node may have changed meanwhile? Or do you mean that the vocabulary has changed (eg. terms have been added)? If you can explain which problem you're trying to solve and how your site should work, I can answer your question better.
Thanks for Getting Back
For example, we have a content type named "contact info" and a State vocab with the individual state terms. A user creates "contact info" content and selects Minnesota and Wisconsin terms when adding the content. A different user goes in, changes the content and unselects the Minnesota term. Instead of updating the content to have only the wisconsin term, I need to add a new piece of content with the Wisconsin term instead of updating the content - if that makes sense.
Basically, when a user edits a node then submits it, I need to use a hook (not sure if its form_submit or nodeapi or something else) to perform some logic to decide whether to update the node or create a new node and perform the correct operation accordingly.
If I understand you
If I understand you correctly, I think I'd go about it something like this...
1. Add a new 'submit' handler to the form, via hook_form_alter.
2. In the new 'submit' handler, check if the taxonomy has changed.
Or something like that... (the above is completely untested!)
Does that sort of sound like what you're looking for?
Yes - Exactly
Thanks,
That is what I'm looking for. I will work off that and get back to you once figured out.
You can use hook_form_formID_alter
If you decide to go this route, you can use hook_form_formID_alter and then you don't need to do the check for the form ID.
http://blog.marceisaacson.com
I think you don't even need
I think you don't even need to add a submit handler. You can implement hook_nodeapi (see http://api.drupal.org/api/function/hook_nodeapi/6) and do your logic when $op = 'presave'.
As you can see in the node_save() function (http://api.drupal.org/api/function/node_save/6), the node will be inserted as new if the nid is empty. The nodeapi presave hook is invokes right before this check.
Thanks for all the feedback
I was able to get it working using the submit handler. However, instead of using a form id, I had to check if the form had the site taxonomy field in it (otherwise would have to enter a form_id for every content type that uses the taxonomy (also, we're using the content_taxonomy module, so the fieldname for the taxonomy is a little different:
This works great. However, it would be nice to just use the node_api hook as mentioned by marcvangend. If I get time to revisit or a chance to refactor, I will check this route out as well.
Again, Thanks for everyone's help. I