Replace hard coded Add new comment in field--comment.html.twig

Created on 7 June 2018, over 6 years ago
Updated 6 January 2025, 4 days ago

To respect the way of Drupal to become more and more a modular and flexible content framework builder and to embrace the split of content and structure we should remove such hard coded introduction labels from the 1990s in twig files and should leave it to the user to add their own interaction note text regarding the several use cases the new uncoupled comment entity can be used for.

Think of user profile "timeline" posts or discussion like arrangements where "comments" are coequal to the initiating created content in a queue. "Add new comment" should be an option but should not be set up by default, which needs theme overrides while this is rather a functional decision, not a theme style decision.

This is why I vote for removing {{ 'Add new comment'|t }} from the field--comment.html.twig template file in line 39.

I could go even further regarding some of such cases, or why we even call it "comments" now, since we uncoupled it as a kind of reaction system which can be added to any entity, but I didn't wanted to go like a bull at a gate for that moment. :)

Solution 1

Replace it with a new {{ value }} which can be filled in an input field in UI added to the comment entity manage form setup or in the respective field setup of the connected entity where this comment type is added.

Solution 2

Change the line to reflect the given label of the comment type field like {{ 'Add new'|t }} {{ label }}. This way the interaction text will reflect the given label of the comment type. If the comment field label/name is "Discussion post", it will print "Add new Discussion post" instead of "Add new comment".

Some more thoughts on this

  1. Regarding possible worries in case of Solution 2 and existing installations where the Add new text would change then, it should be noted that in most cases the label of the used comment types is something like Comment(s) or Node comment or Article comment etc., something similar. So it won't break any view. But we maybe need a plural/singular conversion here (twig?).
  2. On the long run I would rather recommend Solution 1 because it keeps more freedom of choice. But it would be a little bit more work and needs a default setup which fallsback to how it was before. So the input field would have a "Add new comment" typed in already as a default value.
  3. On the other hand, @Dries was very exited about https://www.drupal.org/project/react_comments for understandable reasons and I don't know how big the chances are that we will implement this into core one day. It that's the case we maybe should not put too much effort in here. That's why I added Solution 2.
📌 Task
Status

Closed: duplicate

Version

9.4

Component

comment.module

Created by

🇫🇷France dqd London | N.Y.C | Paris | Hamburg | Berlin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • You make a compelling argument for enhancing Drupal's flexibility by removing hard-coded labels in the Twig files. By doing so, it would enable users to invisalign treatment customize interaction notes according to various use cases, such as user profile "timeline" posts or discussion-like setups where comments are coequal with the initiating content.

Production build 0.71.5 2024