开发者

Customise comment form look and feel

I have a drupal 7 site and want to customize the comment form to always be plain text (regardless of the user and whether they are authenticated). As the text format setting will be fixed, I want开发者_JAVA百科 to remove the little blurb that appears at the bottom of the comment body.

In general, how do I go about customising the look and feel of the comment form?

UPDATE

As per Berdir's instructions I added an #after_build function. I did this by adding a hook_form_comment_form_alter function to my template.php file. That new function and the custom function it calls are below:

function mytheme_form_comment_form_alter(&$form, &$form_state, &$form_id)
{ 
    $form['comment_body']['#after_build'][] = 'configure_comment_form';
    //$form['comment_body']['und']['#after_build'][] = 'configure_comment_form';
}

function configure_comment_form(&$form, &$param1, &$param2)
{
    var_dump($form);
}

Clearly I can tell that my configure_comment_form function is getting called as the var_dump gets printed out. I've tried adding the configure_comment_form to the #after_build at both the location in the $form array shown in the code. I get identical results for both, the comment body form field simply disappears.

I've not overwriting any existing after build functions. $form['comment_body']['#after_build'] does not exist when I add a function to it and $form['comment_body']['und']['#after_build'] looks as below after adding the custom function:

["#after_build"]=>
      array(2) {
        [0]=>
        string(30) "field_form_element_after_build"
        [1]=>
        string(22) "configure_comment_form"
      }


To remove the filters box under the comment body you can use your theme's template.php to implement the following hooks:

function theme_filter_tips($variables) {
    return '';
}
function theme_filter_tips_more_info() {
    return '';
}
function theme_filter_guidelines($variables) {
    return '';
}

This just leaves the outline of the filter/tips box, and that can be taken care of in your theme's CSS with:

.filter-wrapper {
    display: none;
}

Although I am not sure if that will cause other functionality to break by hiding that class.


I've done something similiar for http://drupal.org/project/privatemsg

First, add an #after_build function to the body form field like this "'#after_build' => array('privatemsg_check_format_access')," (since you are altering a form, first check if there is already such a function then append it, don't override)

Then, in that function, you set #access of the format field to FALSE and force the #default_value to whatever you want. See privatemsg_check_format_access

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜