Adds reply, edit, delete, etc. links, depending on user permissions.
Drupal\comment\Comment $comment: The comment object.
Drupal\node\Node $node: The node the comment is attached to.
A structured array of links.
function comment_links(Comment $comment, Node $node) {
$links = array();
if ($node->comment == COMMENT_NODE_OPEN) {
if (user_access('administer comments') && user_access('post comments')) {
$links['comment-delete'] = array(
'title' => t('delete'),
'href' => "comment/{$comment->cid}/delete",
'html' => TRUE,
);
$links['comment-edit'] = array(
'title' => t('edit'),
'href' => "comment/{$comment->cid}/edit",
'html' => TRUE,
);
$links['comment-reply'] = array(
'title' => t('reply'),
'href' => "comment/reply/{$comment->nid}/{$comment->cid}",
'html' => TRUE,
);
if ($comment->status == COMMENT_NOT_PUBLISHED) {
$links['comment-approve'] = array(
'title' => t('approve'),
'href' => "comment/{$comment->cid}/approve",
'html' => TRUE,
'query' => array(
'token' => drupal_get_token("comment/{$comment->cid}/approve"),
),
);
}
}
elseif (user_access('post comments')) {
if (comment_access('edit', $comment)) {
$links['comment-edit'] = array(
'title' => t('edit'),
'href' => "comment/{$comment->cid}/edit",
'html' => TRUE,
);
}
$links['comment-reply'] = array(
'title' => t('reply'),
'href' => "comment/reply/{$comment->nid}/{$comment->cid}",
'html' => TRUE,
);
}
else {
$links['comment-forbidden']['title'] = theme('comment_post_forbidden', array(
'node' => $node,
));
$links['comment-forbidden']['html'] = TRUE;
}
}
// Add translations link for translation-enabled comment bundles.
if (module_exists('translation_entity') && translation_entity_translate_access($comment)) {
$links['comment-translations'] = array(
'title' => t('translations'),
'href' => 'comment/' . $comment
->id() . '/translations',
'html' => TRUE,
);
}
return $links;
}