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
  • 30.7k
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
  • 82.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
  • 16.7k
6 votes
Accepted

How to remove the word "New" for the new comments

copy /modules/comment/comment.tpl.php to your theme folder e.g. sites/all/themes/mytheme/(templates/)comment.tpl.php. That theme file will override the comment.tpl.php from core, in that file you can ...
Andre Baumeier's user avatar
6 votes
Accepted

How to make a comment only visible to the commenter before approval?

Things you need to know: hook_node_view hook_query_TAG_alter db_or Step I read code. Step 1: find function comment_node_view this function define element comment in array render of node. Step 2 find ...
MrD's user avatar
  • 6,078
6 votes
Accepted

How can a poster of a comment notify selected users about a new comment?

When I write a comment on a node, I want to be able to select the users that will get a notification about that new comment. 1) Download Rules and Entity Reference Modules. 2) Enable Rules, Rules UI (...
No Sssweat's user avatar
  • 30.7k
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,253
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
  • 30.7k
5 votes
Accepted

How to replace 'reply' link with button?

There are two methods below. Both are equally effective except the second one requires that the <button> element be taken out of the list of links and put elsewhere in the template. This is ...
othermachines's user avatar
5 votes
Accepted

How may I schedule when comments can be Opened and Closed?

That should be as simple as: function MYMODULE_node_view($node, $view_mode, $langcode) { if (/* Your logic to determine that comments are closed here */) { $node->content['comments']['#...
Clive's user avatar
  • 165k
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
  • 82.3k
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
  • 30.7k
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,826
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,339
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
  • 165k
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,032
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
  • 94.8k
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
Accepted

Question about part of Comment.module

For reference, this is in the comment_view() function. It is equivalent to this, which makes it a little easier to understand: if ($is_threaded) { if ($comment->divs <= 0) { $prefix .= ...
rooby's user avatar
  • 14.7k
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

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

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,469

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