When looking to achieve the goal of adding comments to a custom entity type, I found that in Drupal 8 comments are added to entities with a special field. In order to use this new field, you must first setup a new Entity Type, Bundle, and Comment Type. Here are the steps to do just that.
In this example, I’m using the Entity Construction Kit to create the custom entity type and bundle. I don’t have too much experience with this module at the moment, but so far it seems great!
- Create Entity Type
- Create Bundle
- Create Comment Type
- Add Comment field to new Bundle
#1 Create a new Entity Type
Using the ECK module, you can do this by browsing to
/admin/structure/eck/entity_type. I’ve named mine “Example Custom Entity”.
#2 Create a new Bundle for that Entity Type
Using ECK, add a new bundle to this entity type by selecting “Bundle list” from the dropdown beside your newly created entity type. I’ve named mine “Example Custom Bundle”
#3 Create a new Comment Type
Next, we need to add a new Comment Type that will be used with our new Entity Type. Be sure to enable the Comment module, then browse to
/admin/structure/comment and click “Add comment type”. I’ve named my new comment type “Example Comment Type”.
#4 Add a Comments field to the new Bundle
Now we’re ready to hook them up! Visit your new bundle and click “Manage Fields”. Then select the “Comments” field, and click next to configure it.
#5 Select your new Comment Type & Configure the field
On the next screen you will select the new comment type you created earlier and “Save field settings”.
Then, you will be presented with the familiar comments configuration options which in previous versions of Drupal were stored along with the bundle settings.
#6 Voila! All Done
We now have a custom entity type, custom bundle, and custom comment type all linked up and ready to go.