2

I found an article about wrapping all comments (http://scito.ch/content/wrap-comments-collapsible-fieldset), but I just want to wrap comment replies in a collapsible fieldset.

How do I achieve this?

2

Implement hook_form_alter() or hook_form_FORM_ID_alter() and add the collapsible fieldset to the form field. For example:

function MODULE_form_comment_form_alter(&$form, &$form_state, $form_id) {
    //Create the fieldset
    $form['custom_fieldset'] = array(
        '#type' => 'fieldset',
        '#title' => t('My Collapsible Fieldset'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
    );

    //Move the field into the fieldset
    $form['custom_fieldset']['comment_body'] = $form['comment_body'];

    //Unset the original field
    unset($form['comment_body']);
}

You can set '#collapsed' => TRUE if you want the fieldset to be closed by default.


If you're looking for a Module based approach, you may want to look into the Field group project.

I'm not sure how well this module will get along with the Comment module though. You may need to implement hook_form_alter() in a custom module or in your theme.

5
  • $form['comment_body'] contain my custom define field,so how can i just warp comment reply?
    – younger870
    Jul 9 '12 at 3:51
  • Ah, I may have misunderstood your question. Are you wrapping the actual comments or the reply entry field?
    – Citricguy
    Jul 9 '12 at 4:08
  • just the reply entry field.because if many people post a comment reply in the same comment,the comment reply list so long so i want to collapse it
    – younger870
    Jul 9 '12 at 4:15
  • WIll you add your custom defined code to your question? I think I need to see it to move forward. :)
    – Citricguy
    Jul 9 '12 at 4:25
  • i use orginal drupal 7.14 with comment module and zen template.and also install ideal comment.i have not custom defined some code.Thank you again.
    – younger870
    Jul 9 '12 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.