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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 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.