Skip to main content
10 votes

How to make the comment author name required for anonymous users?

I found the answer: Implementing the hook_form_FORM_ID_alter() hook you can use the comment form id (comment_comment_form) to alter the form. The problem was that the field name is inside the author,...
Adrian Cid Almaguer's user avatar
9 votes
Accepted

How do I add Emoji smileys?

According to Drupal 7.50 released, Emojis were added as a new feature in 7.50 Support for full UTF-8 (emojis, Asian symbols, mathematical symbols) is now possible on MySQL If content ...
No Sssweat's user avatar
  • 31.4k
7 votes
Accepted

How do I get comment form?

See https://api.drupal.org/api/drupal/core%21modules%21comment%21src%21CommentLazyBuilders.php/function/CommentLazyBuilders%3A%3ArenderForm/8.2.x. You create a comment entity and then get its form. &...
Berdir's user avatar
  • 83.3k
7 votes
Accepted

How do I get a list the comment types' machine name?

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 $...
Jaypan's user avatar
  • 17.7k
6 votes

How to get the node id the comment is attached to in hook_comment_insert?

the correct way to load nid is, $entity->get('entity_id')->target_id and not $entity->get('entity_id')->value In case of doubt which key to use, try, $entity->get('entity_id')->...
D34dman's user avatar
  • 326
6 votes
Accepted

How to move the comment form to the top?

You can in field--comment.html.twig {# /** * @file * Default theme override for comment fields. * * Available variables: * - attributes: HTML attributes for the containing element. * - ...
No Sssweat's user avatar
  • 31.4k
5 votes

Sorting comments from newest to oldest

As CommentStorage::loadThread adds comment_filter tag to its query, you may use hook_query_TAG_alter hook to change comments order: /** * Implements hook_query_TAG_alter() for comment_filter tag. * ...
Stanislav Agapov's user avatar
5 votes

How to get the node id the comment is attached to in hook_comment_insert?

This is a late answer based on another question flagged as duplicate of this one. The Comment entity has some helpful methods for getting back the entity it's associated with. CommentInterface::...
mradcliffe's user avatar
  • 5,916
5 votes
Accepted

Send notification E-Mail to x when x’s content is commented

Use Rules module. Create the following Rule: Event: after saving a new comment. You will probably want to restrict this by content type as well. Add action: send mail. Arguments: To: switch to data ...
Aram Boyajyan's user avatar
5 votes

How do I add Emoji smileys?

You might want to have a look at Smiley Smiley is a text filter that substitutes text emoticons, like :-) with images. It comes with a set of example smileys, but you can import ready-to-...
Neograph734's user avatar
  • 8,429
5 votes
Accepted

How to remove (not verified) status in anonymous comments?

You can implement hook_preprocess_username and remove the extra variable: function THEME_preprocess_username(&$variables) { $variables['extra'] = ''; }
Clive's user avatar
  • 167k
5 votes

How to remove (not verified) status in anonymous comments?

It's also possible to change that in the backend. Appearance » Settings » uncheck User verification status in comments in the Page Element Display section
nihilistenhymne's user avatar
5 votes
Accepted

Drupal 8, make comment subject a required field

Here is how, you will need to create a custom module , and add this ... to yourmodule.module file ... /** * Implements hook_form_alter(). */ function yourmodule_form_alter(&$form, \Drupal\Core\...
taggartJ's user avatar
  • 2,190
5 votes
Accepted

Cycle comments on field--comment.html.twig

You can try something like this: {% set pre_render = comments['#pre_render'] %} {% for key, item in comments if key|first != '#' %} {% if key != 'pager' %} {% set item = { '#...
4uk4's user avatar
  • 101k
5 votes
Accepted

Comments on user profile not working

Each Comment Type can only be applied to one type of entity (nodes (content), users, and taxonomy terms are examples of different types of entities). By default, Drupal core only provides a comment ...
Patrick Kenny's user avatar
4 votes

Sorting comments from newest to oldest

Assuming your comment field's machine name is field_comments, put this code into a module to get descending comments. I was having trouble with threaded comments, but this works since it alters the ...
echo's user avatar
  • 1,499
4 votes
Accepted

How to remove reply link?

You can implement template_preprocess_comment() in your module file or theme's template.php file. And check if comment has Parent Comment ID (pid), if yes then remove reply link. /** * Implements ...
Yogesh's user avatar
  • 3,193
4 votes
Accepted

How do I access the loaded comment object?

It is better to use kint() function of the devel module for debugging entities because you will get also a list of available public methods. You cannot get all comment fields values by looping them ...
Andrew Nim's user avatar
4 votes

How do I add Emoji smileys?

Emoji's are also commonly referred to as Smileys. Take a look at the Smiley module for Drupal 7.
Wim Mostrey's user avatar
  • 2,827
4 votes
Accepted

Comment Display

Take /core/modules/comment/templates/comment.html.twig file from your Drupal installation directory and place it in the directory of the theme that you are using in the templates folder, for example /...
PhilippVerpoort's user avatar
4 votes
Accepted

Conditionally hide the node comments via preprocess function

$variables['content']['comment']['#access'] = FALSE; That should work, assuming you use the default comment field named "comment", otherwise whatever you named it. Comments are just a field, nothing ...
Berdir's user avatar
  • 83.3k
4 votes
Accepted

How to notify users when a new comment is posted in the same page as they did?

Have a look at this rule (in Rules export format), which does what you're asking for: { "rules_notify_commentors_about_new_comment" : { "LABEL" : "Notify commentors about new comment", "...
Pierre.Vriens's user avatar
4 votes
Accepted

How to render author custom fields info on comment and node twig template?

For Node: {{ node.getOwner.field_first_name.value }} {{ file_url(node.getOwner.user_picture.entity.fileuri) }} {{ node.getOwner.uid.value }} For Comment: {{ comment.getOwner.field_first_name.value }...
No Sssweat's user avatar
  • 31.4k
4 votes
Accepted

How to count the number of comment and flag in a node?

For the comment count you can get it in the node twig by: {{ content.comment['#items'].comment_count }} But the flag count i think there is no way to get it directly in the twig: There is extension ...
berramou's user avatar
  • 7,255
4 votes
Accepted

Confirmation message on comment submission

Drupal already shows a similar message, to the users who has the post comments permission but not the skip comment approval permission. There is no need to use custom code for that: Don't give the ...
apaderno's user avatar
  • 97.6k
3 votes
Accepted

How to convert username to hyperlink in comment reply similar to StackExchange?

You are looking for the Mentions module: The Mentions module offers Twitter like functionality, recording all references to a user's username - using the [@username] or [@#uid] filter format - from ...
AjitS's user avatar
  • 10.9k
3 votes
Accepted

How to disallow node authors to change node content if comments were submitted for that node?

If coding this is an option, you should look at hook_node_prepare. As mentioned there on the first line: Act on a node object about to be shown on the add/edit form. A code snippet idea that ...
Stefanos Petrakis's user avatar
3 votes

How can I send an email to the previous comment author when a user places a new comment?

There are two situations and they might be a bit hard to combine. Drupal has a concept of threading comments, where the last comment is not necessarily the last in line. Like this: - Comment 1 - ...
Neograph734's user avatar
  • 8,429
3 votes
Accepted

Where to put dpm (Devel) to see comment elements?

You would put it in comment.tpl.php dpm($content); or in templates.php (located in sites/all/themes/yourtheme) inside a preprocess function function MYTHEME_preprocess_comment(&$vars) { dpm($...
No Sssweat's user avatar
  • 31.4k
3 votes
Accepted

500 error when deleting node with 300,000 comments

I think you could delete the comments via database, limiting the deletion to those attached to the involved node. It might be a simple as this: DELETE FROM comment WHERE nid = <the involved node ...
cFreed's user avatar
  • 289

Only top scored, non community-wiki answers of a minimum length are eligible