Comments

Keywords: 

Some Web sites let people comment on pages. Drupal lets you add that feature to your IS.

You enable comments by adding a comment field to a content type. If you wanted to let people comment on projects, you would have to add a comment field to the project type.

Once you have a comment field on a content type, you can control whether each node allows comments. For example, you have two projects, Hang the Lawyers, and Hang the Demons. One of them might attract comments from trolls. You can turn comments off for that project, but leave comments open for the other.

You need to decide:

  • Who gets to see comments.
  • Who gets to add comments.
  • Whether comments have to be approved before they show on the IS.
  • Who gets to approve comments.
  • What type of data comments can contain. For example, you can let people add pictures to comments. Or not.

Adding comment fields to content types

This ain’t no thing, honey! Go to Structure | Content types, pick your content type, Manage fields, and Add field. Select Comment as the field type.

Field type

Give it a label, as usual.

Adding a comment

Now Field settings. You can create more than one comment type, adding your own fields to it. Let’s just use the default comment type.

Settings

Now some more settings.

Settings

The default in the image says that new nodes will have comments on by default. If you want to turn them off for one of the nodes, you need to edit the node.

You get to control where the comments appear on nodes. Usually, they’re after everything else.

Display order

Your choice, though.

Comments are fields on nodes

If you add the field Tongue length to the sloths content type, every sloth node has that field. The field’s value could be 4 inches for one sloth, 6 inches for another, and 5 inches for yet another.

It’s the same with comments. When you add a comment field to project, each project has the field. Comments can be turned on and off separately for each node. For example, here’s the project Eros Esse Valde:

Node setting

People can add comments to the project. Here’s project Ideo Odio:

Node setting

The comments are hidden. Nobody can add comments, and any comments that were already made are not displayed.

Georgina
Georgina
Question. When you add the comment field to a content type, you can set defaults of comments, being open, closed, or hidden. OK, so that will be the setting for new nodes of the content type. But what about nodes that already exist? Say you add a comment field to the project content type, and you already have some project nodes. Will comments for them be open, or what?
Ruben
Ruben
Wow, great question, Georgina! The existing nodes won’t have comments turned on. You have to go back and do that, if you want them to have comments.

Permissions

Permissions. You need ‘em. Check these out.

Permissions

Anonymous users can see comments and post comments. Skip comment approval isn’t checked for anons, so their comments are not shown right away. They need to be approved.

Org managers can Administer comments and comment settings. That means they can approve comments posted by anons. Org managers have Skip comment approval. So when they post comments, the comments appear immediately.

Approving comments

In the admin menu, Content | Comments | Unapproved comments shows Org managers the comments they need to check.

Comment approval

You can figure out how it works.

In an exercise earlier, you made a control panel, a menu for managers to use. There’s one on Gamerz, too. Log in as an org manager, and you’ll see it. Go to the login page. (https://gamerz.cybercour.se/user/login) Log in with the user name manager, and the password password.

New CP

There’s a link to the comment approval page at the bottom.

How to add a link like that? The CP is a menu. Go to Structure | Menus, and add a link to the CP menu.

We need to know the URL of the comment approval page. Easy. Just go to the page, and look at the URL:

URL

Use the URL for the new menu link, without the domain name:

Adding menu item

That’s it! W00t!

Text formats

So, anons can post comments on projects. Org managers can approve them. Cool.

Another question. Can anons put anything in a comment, like photos? Just plain text? What?

Remember that there are text formats, also called filters. Full HTML lets people type any HTML. Restricted HTML lets them use just a few tags. Plain text means they can’t type any HTML tags at all. Just, er, plain text.

Adela
Adela
Let’s make it plain text for now. We can change it later if we want.
OK. Go to Permissions | Filters, and set it up to be like this:

Filter permissions

Marcus
Marcus
Wait, what? Anons can’t use any of the formats? Will they be able to type anything?
Drupal gives every user access to plain text. It doesn’t bother adding it to the filter list.

Here’s what the new comment form looks to anons:

Comment form

There’s no toolbar in the comment field. Just a place to type. That’s it.

The Projects view

The Gamerz IS has a view that shows a list of projects. Let’s add a comment count:

Comment count

Turns out that Views already knows how to count comments. It has a special field for it.

Open the view, and add the field:

Comment count field

It doesn’t have many settings. Let’s just give it a label.

Label

Move the field to the right spot:

Field order

Recall that Org managers see an Edit link for each project. I put the comment count above that.

Save the view, and we’re done. Woohoo!

Exercises

Exercise: Slothy comments
Let people make comments about sloths.
  • Anons can see and make comments, but they have to be approved.
  • Create a role called Social manager. Users with that role can approve comments. They can post comments without approval.
  • Anons can use the Restricted HTML filter.
  • Add CAPTCHA to comment forms. Hint: try “comment_comment_form” for the CAPTCHA point.
Submit the URL of a sloth’s page, and log in credentials for user 1.

(If you were logged in as a student, you could submit an exercise solution, and get some feedback.)

Exercise: Comment counting view
Make a view that shows the number of comments on each sloth. Here’s mine:

Comment counts

  • A table
  • Initially sorted by comments, descending
  • User can click on the column headings to sort
  • Header text
Give the URL of the view on your site, and login credentials for user 1.

(If you were logged in as a student, you could submit an exercise solution, and get some feedback.)

Summary

You can add a comments field to a content type. Permissions control who can see and add comments, whether approvals are skipped, and who gets to approve comments. You can add comment counts to views.