function ajax_comments_node_links_alter in AJAX Comments 8
Implements hook_node_links_alter().
File
- ./
ajax_comments.module, line 131 - AJAX comments module file.
Code
function ajax_comments_node_links_alter(array &$node_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.
$links = \Drupal::service('comment.link_builder')
->buildCommentedEntityLinks($node, $context);
foreach ($links as $link_name => $link) {
$field_name = substr($link_name, strlen('comment__'));
$classes = [
'js-use-ajax-comments',
'js-ajax-comments-reply',
'js-ajax-comments-reply-' . $node
->id() . '-' . $field_name . '-0',
];
if (!empty($link['#links']['comment-add'])) {
if (empty($link['#links']['comment-add']['attributes']['class'])) {
$links[$link_name]['#links']['comment-add']['attributes']['class'] = $classes;
}
else {
$links[$link_name]['comment-add']['attributes']['class'] = array_unique(array_merge($link['#links']['comment-add']['attributes']['class'], $classes));
}
}
}
$node_links += $links;
}