I'm building a site for a client with custom content types, and learning a bit about altering Drupal forms at the same time. I'm using custom modules (hook_form_alter, etc) and template.php in the theme to alter the create node forms to make the UI as intuitive and friendly to them as possible. Basically hiding unnecessary fieldsets, unnecessary options (like sticky, promote to front page), that kind of stuff.

I created a CCK checkbox field for them called "Best of Site," basically when they check that box on a node it shows up as a "Best of" in a Views field on the site. On the create form, I think it would make a lot of sense to move that "Best of" checkbox into the publishing options ['options'] fieldset below as it makes more sense there.

And that is where I am stumped. Is there a way in template.php (or a hook in a module) to designate a parent fieldset to an existing CCK field? I tried throwing options in front of it like so ($form['options']['field_bestofsite']) in a phptemplate_node_form function in the template.php file, but that creates a brand new field under Publishing Options, NOT moves the existing CCK field ($form['field_bestofsite']).

Comments

markus_petrux’s picture

Status: Active » Fixed

You cannot move the field somewhere else on the $form structure because each field is expected to be located on a particular position in this structure. Think about validation and submit handlers, after build callbacks, etc.

If this is possible, it should be done while rendering the form. I would try using a pre_render callback that is executed last in the chain of other possible render callbacks. You may need to alter the weight of your custom module to a high enough value to ensure it is executed last.

MondayNgt’s picture

Status: Fixed » Closed (fixed)

I decided to go about this via a different route, writing a custom module to place a checkbox function in the publishing area. Have it mostly working other than trying to figure out how to pass the $node value through hook_form_alter in order to have the checkbox accurately show whether it's been checked or not, but that's another area outside of CCK. Thanks.