I know about CCK but that's not what I'm using. Instead I've created a module to define a custom content type following the instructions found here:
and referencing the node_example.module found here:
http://api.drupal.org/api/drupal/developer--examples--node_example--node...
My module creates a new content type that adds my own custom fields to those of a base node. My custom fields are related in a way that begs for a table layout.
I would like to theme the basic table structure in the module code (ie. not in any .tpl files). I thought I needed the following methods (note that I have more than these in my module, but I though these were the ones related to theming):
1. hook_form() for defining my node's form.
function my_module_form(&$node) {
// define array of form fields in $form here and then...
return $form;
}
2. hook_theme() for declaring a theme function for the theme engine to use for my new form.
function my_module_theme() {
// declare theme function
return array(
'my_module_form' => array(
'arguments' => array('form' => NULL),
),
);
}
3. theme_[item]() for theming the form.
function theme_my_module_form($form) {
// generate $header and $rows arrays from form fields here and then...
return theme('table', $header, $rows) . drupal_render($form);
}
...but it seems I'm wrong.
What is the proper way to customize the html of my custom node fields?
Comments
Are you trying to customize
Are you trying to customize the input (form) or node output?
And what seems wrong about that approach?
Input Form Manipulation
Yes, the node input form. Sorry I didn't state that and thank you for showing interest in my post.
Well, my theme function isn't doing anything with my form elements. I've cleared the cache and reloaded the form with no success.
I assumed either node forms in particular don't allow that method of form theming or I've made a minor error somewhere. I noticed on this page http://api.drupal.org/api/function/hook_nodeapi/6 that perhaps I should be using hook_nodeapi() in conjunction with hook_form_alter().
So should I be using hook_form() to establish my basic node type, hook_form_alter() to add my elements and then hook_nodeapi() with its "prepare" $op to theme? As in:
1. hook_form()
2. hook_form_alter()
3. hook_nodeapi()
If it's the node input form,
If it's the node input form, you can do something like this:
Hopefully this can point you in the right direction.
Contact me to contract me for D7 -> D10/11 migrations.
Yes!
Thank you so much. This is what I was looking for and it absolutely works for what I'm trying to do.
I'll add a note that the placement of the '#theme' element in the $form array seems to be important. I'm assuming the theme engine will only allow me to theme sub-elements of the $form array and not the entire $form array. Putting every element in a $form['wrapper'] sub-element might change that. In either case:
I had luck with:
but not with:
You can use $form['#theme'].
You can use $form['#theme']. Though maybe not for node forms now that I think of it.
Contact me to contract me for D7 -> D10/11 migrations.