This tutorial is part of the “Build a Blog in Drupal 8” series:
If you want to communicate with readers on a blog, the best way to achieve this is by setting up comments. If you’re happy to deal with spam and the occasional troll, then comments are great for communicating with readers and fostering a community.
The functionality has changed a lot in Drupal 8. In Drupal 7, the comments system was fairly rigid. You could only use them on content types and only have a single comment type. If you needed to support multiple comment types like review or feedback, you were out of luck.
In Drupal 8, the comments system has been rebuilt. They can be attached to any entity type by adding a “Comments” field. You can also now have different comment types. This allows you to do all sorts of things like having public and private comments on a single content type.
In the last tutorial, we created a Blog content type and added fields to it. Let’s continue working on it by adding support for comments. We’ll configure the user permissions so that comments can be submitted anonymously, but will need to be approved before they’re published.
Add Comment Field
As mentioned in the introduction, the comment system has changed quite considerably in Drupal 8. Instead of configuring the comments from the vertical tabs on a content type edit form, everything is done through a field.
1. Click on Structure in the toolbar, “Content types” and click on “Manage fields” on the Blog row. Now click on “Add field”.
2. In Drupal’s Standard install profile, it creates a comment field and attaches it to the Article content type. We’ll re-use this field instead of creating another one.
3. Select “Comments: comment” from “Re-use an existing field” and click on “Save and continue”.
4. From the field edit page, you can configure the default value; if the comments should be open, closed or hidden and display settings. If you’ve used Drupal 7, these settings will look familiar.
Once you’re happy click on “Save settings”.
New in Drupal 8 is the ability to have different comment types. This is the same concept as content types. The Standard installation profile creates a “Default comments” comment type, which is used for general comments.
To create and manage comment types, just go to Structure and click on “Comment types”.
Being able to create different types is powerful and this makes the comment module very flexible. Let’s say for example you want to allow users to leave a review, you could then create a comment type called Review with its own fields.
If you now go to your Drupal site as an anonymous user you’ll see that you can’t comment without registering or logging in. Requiring users to register creates a big barrier to entry and sometimes it make sense to allow anonymous comments, but that’s a choice you need to make.
If you do decide to allow anonymous comments make sure you install Honeypot and Mollom. The modules will help to combat spam, it won’t eliminate them totally, but it’ll get most spam comments. Both modules have Drupal 8 versions, but I haven’t tested them so let me know how you go in the comments below.
Let’s now allow anonymous comments.
1. Go to People and click on the Permissions tab.
2. Scroll to the Comment section. Check “Post comments” for anonymous users and make sure “Skip comment approval” stays unchecked. This will allow anonymous users to submit comments but they’ll need to be approved.
Scroll to the bottom and click on “Save permissions”.
When an anonymous user submits a comment, they receive the following message:
To approve comments, simply go to Content, Comments and click on the “Unapproved comments” tab. Check the comment you want to approve, select “Publish the selected comments” and click on Update.
Now the comment will be published and visible on the “Published comments” page. If you want to give another user access to moderate the comments then assign them the “Administer comments and comment settings” permission.
The new comments system in Drupal 8 is very good. Now that comments can be added on any entity type and you can have different comment types, I’ll be curious to see in what innovative way they’ll be used.
How would you use the new comments system in Drupal 8? Tell us in the comments below.