Theming tips and tricks
Altering a Drupal core form theme function to add additional information
This handbook page was inspired by this feature request to the Scheduler module:
Under Administer > Content Management> Content
Please provide a listing under the "STATUS" column which would indicate "Not Published/Scheduled" instead of just "Not published".
It would be even better it said "Scheduled to publish on {date and time}"
The problem here is that the form (inside a table) is generated by Core (specifically node_admin_nodes() and it's associated theme function theme_node_admin_nodes($form) in modules/node/node.module). Although hook_form_alter() would allow a module to alter a form, this page describes how it can be done within the theme layer which is more appropriate to the requested change).
The key to solving this problem in the theme layer is in theme_node_admin_nodes($form). This tells us the table form is theme-able (in fact, all forms are theme-able, you just need to find the form_id string) and this is where we can get at the status text to amend.
This first snippet (which you would place inside your theme's template.php file) is a good start and shows how you can override a form theme function:
<?php
function phptemplate_node_admin_nodes($form) {
if (isset($form['title']) && is_array($form['title'])) {
$nids = element_children($form['title']);
$sql = 'SELECT nid FROM {scheduler} WHERE publish_on > %d AND nid IN (%s)';
$r = db_query($sql, time(), implode(',', $nids));
while ($row = db_fetch_array($r)) {
$scheduled_nids[] = $row['nid'];
}
foreach (element_children($form['title']) as $key) {
if (in_array($key, $scheduled_nids)) {
$form['status'][$key]['#value'] .= '/'. t('scheduled');
}
}
}
// Chain to Drupal's core theme function
return theme_node_admin_nodes($form);
}
?>If you wanted to go that extra step and add Scheduled to publish on {date and time} then this would be what you need:-
<?php
function phptemplate_node_admin_nodes($form) {
if (isset($form['title']) && is_array($form['title'])) {
$nids = element_children($form['title']);
$sql = 'SELECT nid, publish_on FROM {scheduler} WHERE publish_on > %d AND nid IN (%s)';
$r = db_query($sql, time(), implode(',', $nids));
while ($row = db_fetch_array($r)) {
$scheduled_nids[$row['nid']] = $row['publish_on'];
}
foreach (element_children($form['title']) as $key) {
if (array_key_exists($key, $scheduled_nids)) {
$form['status'][$key]['#value'] .= '/'.
t('scheduled to publish on ') .
date(variable_get('date_format_short', 'm/d/Y - H:i'), $scheduled_nids[$key]);
}
}
}
// Chain to Drupal's core theme function
return theme_node_admin_nodes($form);
}
?>I have tested both these theme override functions and they work fine. However, a minor issue/problem with these, especially the second one, is that the Status column only has so much width. That second option widens the column a lot. If you can live with it, fine. Otherwise, have a play and develop your own shorthand.
Notes
Both these theme override functions contain db_query(). What you have to ask yourself here is "I am prepared to live with database functions inside my theme override functions?" It's normal not to do this and there is an alternative. If we did away with the SQL/database part of this snippet we could just use node_load(array('nid' => $key)) in the foreach() loop. This would make the ->publish_on variable available and we could use that instead. However, consider a content table with 30 nodes. That would mean 30 additional SQL queries to the database. The method used above uses one SQL query and makes use of the SQL IN operator. It's faster and more efficient, but to use it, you have to live with DB calls in your theme function (which isn't the end of the World, it does work just fine).
(The snippets above aren't perfect Drupal coding standards as I made sure the line lengths were not too long so they display on Drupal.org ok).

overriding comment_form using theming
Could someone provide further example of how to override comment_form?
http://api.drupal.org/api/function/comment_form/5
Specifically, I am looking in the comment.module to replace....
$form['name'] = array('#type' => 'textfield', '#title' => t('Your name'), '#maxlength' => 60, '#size' => 30, '#default_value' => $edit['name'] ? $edit['name'] : variable_get('anonymous', t('Anonymous')), '#required' => TRUE);with....
$form['name'] = array('#type' => 'textfield', '#title' => t('Your name'), '#maxlength' => 60, '#size' => 30, '#required' => TRUE);I tried adding to my "template.php" file....
function phptemplate_comment_form($form) {return _phptemplate_callback('comment-form', array('form' => $form));
}
and created a "comment-form.tpl.php" file....
<?php$form['name'] = array('#type' => 'textfield', '#title' => t('Your name'), '#maxlength' => 60, '#size' => 30, '#required' => TRUE);
print drupal_render($form);
?>
This eliminates the "Anonymous" pre-fill default value from the field when the page is loaded, but it also results in the following error....
warning: implode() [function.implode]: Invalid arguments passed in /home/.watson/username/domain/includes/form.inc on line 623.I also tried the following in my "comment-form.tpl.php" file....
<?php$form['name']['#default_value'] = 'test';
print drupal_render($form);
?>
and this didn't seem to do anything.
I am guessing that, because I am still learning this, it is a syntax error on my part.
I tried following the examples on http://api.drupal.org/api/file/developer/topics/forms_api.html/5 but am apparently missing something.
Thanks for any help!