A new comment type is created and added as a field (say x_comments) to a custom entity. The comments show up and work as expected. However when the x_comments field is configured to disable 'Show reply form on the same page as comments' the 'Add new comment' link/button does not get rendered on custom entity pages. When this setting is enabled the comment form is displayed as expected.

Inspecting Drupal core's Article content type has custom Links pseudo field where 'Add new comment' link/button is displayed. However my custom entity does not have such a pseudo field, even if it did comment module would not know about it.

Please share clues on how to make the 'Add new comment' link/button be displayed?

The buildCommentedEntityLinks method is not being called on custom entity which creates the 'Add new comment' link. Hmm

1 Answer 1


Turns out one needs to implement field formatter for other entities instead of hook_links_alter. So one can perhaps add a Pseudo field formatter to get this markup rendered on custom entities with an approach described here

The hidden gem is noted in the comments for the node entity.

   * Implements hook_node_links_alter().
  function comment_node_links_alter(array &$links, NodeInterface $node, array &$context) {
    // Comment links are only added to node entity type for backwards
    // compatibility. Should you require comment links for other entity types you
    // can do so by implementing a new field formatter.
    // @todo Make this configurable from the formatter. See
    //   https://www.drupal.org/node/1901110.

    $comment_links = \Drupal::service('comment.link_builder')->buildCommentedEntityLinks($node, $context);
    $links += $comment_links;

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.