public CommentController::renderNewCommentsNodeLinks(Request $request)
Returns a set of nodes' last read timestamps.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request of the page.
Return value
\Symfony\Component\HttpFoundation\JsonResponse The JSON response.
Throws
\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException
File
- core/modules/comment/src/Controller/CommentController.php, line 314
Class
- CommentController
- Controller for the comment entity.
Namespace
Drupal\comment\Controller
Code
public function renderNewCommentsNodeLinks(Request $request) {
if ($this->currentUser()->isAnonymous()) {
throw new AccessDeniedHttpException();
}
$nids = $request->request->get('node_ids');
$field_name = $request->request->get('field_name');
if (!isset($nids)) {
throw new NotFoundHttpException();
}
// Only handle up to 100 nodes.
$nids = array_slice($nids, 0, 100);
$links = array();
foreach ($nids as $nid) {
$node = $this->entityManager->getStorage('node')->load($nid);
$new = $this->commentManager->getCountNewComments($node);
$page_number = $this->entityManager()->getStorage('comment')
->getNewCommentPageNumber($node->{$field_name}->comment_count, $new, $node, $field_name);
$query = $page_number ? array('page' => $page_number) : NULL;
$links[$nid] = array(
'new_comment_count' => (int) $new,
'first_new_comment_link' => $this->getUrlGenerator()->generateFromRoute('entity.node.canonical', array('node' => $node->id()), array('query' => $query, 'fragment' => 'new')),
);
}
return new JsonResponse($links);
}
Please login to continue.