Closed (fixed)
Project:
Node clone
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
28 Feb 2009 at 02:37 UTC
Updated:
3 Oct 2018 at 10:38 UTC
Jump to comment: Most recent
Comments
Comment #1
pwolanin commentedYou could use the alter hook to exclude certain fields.
Comment #2
deviantintegral commentedThanks; I've ended up doing that in a snippet like this:
Comment #4
dinis commentedJust a quick 2c.
I required similar functionality; I setup a rule which instead of changing the code, it checks for new content being saved and inserts a null value into the requred CCK fields where the type is applicable.
Hope this helps someone :)
Danielle x
Comment #5
giorgio79 commentedAny chance of having sg built in the module where we could select fields to be excluded when cloning?
At the moment Danielle's solution only works if sg is saved, but as I understand in 6.x the node clone is edited first and even there I would like to empty some fields.
Comment #6
wgrunberg commented@deviantintegral Do you put the snippet from #2 into your node-.tpl.php file?
Comment #7
deviantintegral commented@wgrunberg, not it's in the site's custom code module in the hook_form_alter() implementation: http://api.drupal.org/api/function/hook_form_alter
Comment #8
wgrunberg commented@deviantintegral Thanks!
Would you mind checking what I am doing wrong with the following? Non of the fiels are populated when clicking on the clone tab. Do I have to account for fieldsets (CCK "groups")?
I used these http://drupal.org/node/416986 guidelines to create my first custom module and used the Devel module to identify field names/arrays.
Comment #9
deviantintegral commentedAs long as you're modifying the right values as shown by dumping the $form array, you should be doing it correctly. You only have to think about fieldsets if the parent element has #TREE set to TRUE. I would double-check to ensure that you have the right form ID.
Comment #10
cdale commentedWhy are people using a form alter for this? Why not use hook_clone_node_alter()? Also, I'm sure the above code will not work most of the time. Maybe in rare cases.
From the post in #8, why not something like the following?
Comment #11
wgrunberg commentedThanks cdale and deviantintegral for helping me!
hook_clone_node_alter() in #10 works nicely. Why wouldn't hook_form_alter() work? Is it specific to Drupal core?
Comment #12
wgrunberg commentedClosed - thanks for the support.
Comment #13
deviantintegral commentedI'm not sure why using hook_form_alter() didn't work - it's currently working fine on a live site. Glad you got it working though!
Comment #14
cdale commentedhook_form_alter() *MIGHT* work for CCK fields if the modules form alter runs before CCK's form alter, and even then, it will only work when the save method for node_clone is prepopulate. However, altering the title like that in a hook_form_alter() will not work, you'd have to edit the values in the actual form field itself, not on #node. So basically, the code in #2 will work in some circumstances and configurations, but not in others, and the code in #8 will never fully work as the title can not be set in the way that is being done there. The code I've provided in #10 should always work regardless of method.
Comment #15
ladybug_3777 commentedFor anyone looking to do this with version 7.x, remember there is an example of the new structure in the clone.api.php file:
I was able to exclude the cloning of a specific field for all my content types by using that hook like this:
Comment #16
ladybug_3777 commentedHmmm... I'm actually thinking setting the fields to NULL might be better. I was looking at the code in the module for the function
_clone_node_prepareand I noticed in there it is setting values to NULL.If that's the case, this may work better (Perhaps someone that is more familiar can chime in on the proper way?)
Comment #17
alex72rm commentedThe solution in #16 seems to be the best approach to solve the issue. Is it compatible with Drupal 7?
Furthermore, my issue is regarding pre-population of a cloned select list where the required field is prefilled automatically with the first element of the list, instead to leave it "empty & required". The prepopulation of certain fields when cloning is a big source of mistakes.