Drupal ships with just one comment type enabled, with the machine name comment. But if the Forum module is installed, there is also comment_forum. And site builders can define new comment types in the GUI.

How do I get a list the comment types' machine name? Or: How can I get all comments, regardless of name.

  • As in, with the Entity API?
    – mona lisa
    Aug 6, 2022 at 21:27

1 Answer 1


Comment types are an entity type, so you can load them as with any entity type, and get the machine name from CommentType::id():

$comment_types = array_map(
  function ($comment_type) {
    return $comment_type->id();

Or to load all comments, regardless of type, you can use:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.