function comment_permalink

Redirects comment links to the correct page depending on comment settings.

Since comments are paged there is no way to guarantee which page a comment appears on. Comment paging and threading settings may be changed at any time. With threaded comments, an individual comment may move between pages as comments can be added either before or after it in the overall discussion. Therefore we use a central routing function for comment links, which calculates the page number based on current comment settings and returns the full comment view with the pager set dynamically.

Parameters

$cid: A comment identifier.

Return value

The comment listing set to the page on which the comment appears.

1 string reference to 'comment_permalink'
comment_menu in drupal/core/modules/comment/comment.module
Implements hook_menu().

File

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

Code

function comment_permalink($cid) {
  if (($comment = comment_load($cid)) && ($node = node_load($comment->nid))) {

    // Find the current display page for this comment.
    $page = comment_get_display_page($comment->cid, $node->type);

    // @todo: Cleaner sub request handling.
    $request = drupal_container()
      ->get('request');
    $subrequest = Request::create('/node/' . $node->nid, 'GET', $request->query
      ->all(), $request->cookies
      ->all(), array(), $request->server
      ->all());
    $subrequest->query
      ->set('page', $page);

    // @todo: Convert the pager to use the request object.
    $_GET['page'] = $page;
    return drupal_container()
      ->get('http_kernel')
      ->handle($subrequest, HttpKernelInterface::SUB_REQUEST);
  }
  throw new NotFoundHttpException();
}