function comment_links

Adds reply, edit, delete, etc. links, depending on user permissions.

Parameters

Drupal\comment\Comment $comment: The comment object.

\Drupal\Core\Entity\EntityInterface $node: The node the comment is attached to.

Return value

A structured array of links.

1 call to comment_links()

File

drupal/core/modules/comment/comment.module, line 918
Enables users to comment on published content.

Code

function comment_links(Comment $comment, EntityInterface $node) {
  $links = array();
  if ($node->comment == COMMENT_NODE_OPEN) {
    if ($comment
      ->access('delete')) {
      $links['comment-delete'] = array(
        'title' => t('delete'),
        'href' => "comment/{$comment->id()}/delete",
        'html' => TRUE,
      );
    }
    if ($comment
      ->access('update')) {
      $links['comment-edit'] = array(
        'title' => t('edit'),
        'href' => "comment/{$comment->id()}/edit",
        'html' => TRUE,
      );
    }
    if ($comment
      ->access('create')) {
      $links['comment-reply'] = array(
        'title' => t('reply'),
        'href' => "comment/reply/{$comment->nid->target_id}/{$comment->id()}",
        'html' => TRUE,
      );
    }
    if ($comment->status->value == COMMENT_NOT_PUBLISHED && $comment
      ->access('approve')) {
      $links['comment-approve'] = array(
        'title' => t('approve'),
        'href' => "comment/{$comment->id()}/approve",
        'html' => TRUE,
        'query' => array(
          'token' => drupal_get_token("comment/{$comment->id()}/approve"),
        ),
      );
    }
    if (empty($links)) {
      $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('translate'),
      'href' => 'comment/' . $comment
        ->id() . '/translations',
      'html' => TRUE,
    );
  }
  return $links;
}