So, What Makes the Drupal 8 Comments far More Tempting?
1. They’re set up as fields
2. Comments have their own fields
3. They’re of several types
4. Comments have their own area now
5. The “Recent Comments” block is in Views
And Here’s How You Can Create Your Comments in Drupal 8
Basically, the whole process comes down to 2 major steps:
- You create a comment entity in code.
- Then you save it.
- entity_type: it’s the entity that you attach your comment to (a node, for instance)
- entity_id: it’s the id that you’ll attach the comment to (it would have to be a nid in case it’s a node that you’ll attach it to)
- field_name: this field is the one for the entity that you’re attaching your comment to
- uid: informs Drupal which user wrote a specific comment
- comment_type: the type of comment you want to create (you know, who’ve already talked about how in Drupal 8 you have several types of comments to juggle with). The default comment will be just comment
- subject: just like a node comes with a title field, so does a comment come with a “subject field” in Drupal 8
- comment_body: is provided by default and you can remove it, just like you can remove any other one of the fields
- status: if you don’t want, as admin, to be asked to approve each comment before it goes live, set it to 1
- field_foodbar: although it does not show in the above example of code, we still wanted to show you that you’re free to add custom fields if you want to. Simply use the field’s machine name and give it a default value.
We do Web development
Go to our Web development page!