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.2k
8 votes
Accepted

How to show Comment Count in node template?

Use this code in your theme's YOUR_THEME.theme file: function YOUR_THEME_preprocess_node(&$variables) { // Note: you'll probably want this only for certain content types. if ($variables['node'...
Aram Boyajyan's user avatar
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.1k
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.4k
6 votes
Accepted

Hide "Your name" field in comment form from everyone except admin

function YOURMODULE_form_comment_form_alter(&$form, &$form_state) { global $user; if ($user->uid != 1) { unset($form['author']['name']); } } Another way is, if your theme has a ...
DRUPWAY's user avatar
  • 7,383
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.2k
5 votes
Accepted

add comment form in views

<?php $comment = new stdClass; $comment->nid = $row->nid; $form = drupal_get_form('comment_form', $comment); print render($form); ?> Works for me. Make sure that your Content: Nid field ...
No Sssweat's user avatar
  • 31.2k
5 votes
Accepted

Disallow HTML in comments

The Allowed Formats projects allows you to control the available text formats per field, so you can limit it to plain text. Better Formats is a similar module. You could do the same with a form alter ...
Berdir's user avatar
  • 83.1k
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,917
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,409
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,132
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
  • 99.2k
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

Hide "Your name" field in comment form from everyone except admin

If you have more than one users having administrator role then you may use this snippet. Place this piece of code at the bottom of template.php of your current theme. Note: Replace YOUR_THEMENAME ...
WaQaR Ali's user avatar
  • 1,688
4 votes
Accepted

How to print a message when a Pane is empty?

Create a new pane with that text and set a visibility rule on it - there should be an existing rule that you can use. If not a ctools rule plugin is pretty simple to write and you can have that rule ...
Scott Hooker's user avatar
4 votes

How to hide the 'Format Options' / 'Help Text' Guideliness from the bottom of comments textarea?

The best is to add to your CSS file .filter-wrapper { display: none; } There you go, disappeared!
adigunsherif's user avatar
4 votes
Accepted

How can I get comment creation date?

/** * Implements hook_preprocess_comment */ function THEME_NAME_preprocess_comment(&$variables) { // Getting the node creation time stamp from the comment object. $date = $variables['comment']-...
Vamsi's user avatar
  • 2,116
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,489
4 votes
Accepted

Display all comments of node without pager (300+ comments)

It's stored in a variable per content type, you can override it like so: variable_set('comment_default_per_page_CONTENT_TYPE', 500); Where CONTENT_TYPE is the machine name of the content type. If ...
Clive's user avatar
  • 167k
4 votes

How do I remove or hide the Permalink in comments?

Just tried your idea (remove <p class="comment__permalink">{{ permalink }}</p> from comment.html.twig) and it works as expected. Important: Don't forget to rebuild your cache: drush ...
Stefanos Petrakis's user avatar
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,183
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

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