Posted by Chiaroscuro on July 23, 2007 at 2:36pm
Hi guys, I am a recent drupal user.
I am trying to understand how to re-theme the comment/reply node.
As suggested by some online resources, I have ripped comment_form from comment.module and I have renamed it mytheme_comment_form inside a template.php file inside my new theme, but to no avail..
Both the original function and my function get called by the theming engine, but my function returns different results and the comment form doesn't display..
any idea on what steps I could take?
--kia
Comments
Theming the reply form is
Theming the reply form is different from theming the actual reply. theme_form functions take the $form array as an argument and wrap HTML around calls to drupal_render().
Here's an example of what I mean.
<?php
function my_comment_form(){
$form = array();
$form['subject'] = array('#type' => 'textfield');
$form['body'] = array('#type' => 'textarea');
return $form;
}
function theme_my_comment_form($form){
$output = '';
$output .= '<table><tr><td>'. drupal_render($form['subject']) .'</td><td>'. drupal_render($form['body']) .'</td></tr></table>';
$output .= drupal_render($form);
return $output;
}
?>
You want to do the last drupal_render($form) because Drupal has already put in all the necessary, hidden parts to the $form, and those need to be rendered. drupal_render knows that it has already done 'subject' and 'body', so those won't be displayed again.
Study comment_form() to see which elements you really need to worry about. I looked at it myself, and most of it is #value = 'value' which are invisible to the browser.
Drupal should call theme('comment_form') on its own, so putting yourtheme_comment_form in template.php should work. If not, just call it theme_comment_form.
-----
Übercart -- One cart to rule them all.
theme_comment_form doesn't seem to work..
thanks for your answer IslandUsurper.
I tried with theme_comment_form and tried with phptemplate_comment_form and with mythemename_comment_form, but all these functions get called but return a different output..
the signature of the function however is
function theme_comment_form($edit, $title = NULL) {
and not
function theme_comment_form($form) {
where you refering to a different internal mechanism?
anyway, this is an excerpt of the $form generate by drupal (and it works):
Array
(
[_author] => Array
(
[#type] => item
[#title] => Your name
[#value] => admin
)
[author] => Array
(
[#type] => value
[#value] => admin
)
[subject] => Array
(
[#type] => textfield
[#title] => Subject
[#maxlength] => 64
[#default_value] =>
)
etc...
this is generated by my code (copied from comments.module and left unchanged) and it doesn't work:
Array
(
[admin] => Array
(
[#type] => fieldset
[#title] => Administration
[#collapsible] => 1
[#collapsed] => 1
[#weight] => -2
[name] => Array
(
[#type] => textfield
[#title] => Authored by
[#size] => 30
[#maxlength] => 60
[#default_value] => Array
etc..
I feel really lost, any help is appreciated.
cheers
theme_comment_form shouldn't
theme_comment_form shouldn't mimic what comment_form does. The function signature is indeed
<?phpfunction theme_comment_form($form);
?>
and $form is the return value of comment_form() plus all the necessary stuff Drupal puts in. Your code shouldn't make a form array at all. That's the job of comment_form. Instead, you need to output the markup that goes around the form elements.
Take a look at the Form Quickstart Guide, particularly point 2 under "Theming Forms".
-----
Übercart -- One cart to rule them all.
<?php function
<?phpfunction theme_comment_form($form);
?>
Yes, it does get called, but what you return is ignored, which is unlike any other theming function in Drupal.