Drupal customize comment subject field?

2 posts / 0 new
Last post
Drupal customize comment subject field?

By default, Drupal 6 gives me the option to enable or disable the comment subject field. To keep the comment form lean and clean, I prefer to disable the comment subject field for our users. However, that also means that by default, the clickable link text of the comment (ie. comment subject), will simply be the first few words of the first sentence of the comment. The drawback to this is that, in the "recent comments" block (or anywhere else comments are referenced), the comment link title no longer gives a good indication of the subject matter of the comment.

Therefore - it would be ideal if I could keep the comment subject field disabled to make life easier for my users, but give me the option, while approving comments, to add/ edit the comment subject field.

Can this be done in Drupal 6?

No votes yet
Select your preferred way to display the comments and click "Save settings" to activate your changes.
Customizing Drupal's Subject Comment Field

Hi DrupalJunkie,

Excellent question. There's two solutions to your approach. The simple one, and the more extended, customizable one. It is possible to actually theme the comment form, giving you more or less complete control over its look and elements. But to simply achieve the functionality you're looking for, you could also take this approach:

For content types (such as page) that you wish to have the comment subject field only show up for logged in users that meet a specific role requirement, you can add the following code to your template file(s) (in this example, we use the page content type, or page.tpl.php):

global $user;
$admin = false;
$allowed = array('content-admin','editor');
foreach($user->roles as $role){
  if(in_array($role, $allowed)) {
      $admin = true;

<?php if ($admin == false) { print '<div class="logged-out">'; } ?>
<?php print $content; ?>
<?php if ($admin == false) { print '</div>'; } ?>

Basically what this does is wrap the content in a "logged-out" div for users that are not logged in and do not belong within a certain role (content admin and editor in this case). Next, we simply kill the subject comment wrapper for logged out (anonymous) users by adding this statement to our theme's style sheet (styles.css):

.logged-out #edit-subject-wrapper { display: none }

Note that you'll need to enable the comment subject field for this page content type for this to work. What the code snippet does is check to see if a user is logged in and if that user belongs to a certain role. If they don't, the comment subject field (which is optional), will simply be hidden from the comment form.

The content of this field is kept private and will not be shown publicly.

We use this trick question to try and prevent automated spam comments.