label(), 'node/' . $node->nid))); $op = isset($_POST['op']) ? $_POST['op'] : ''; $build = array(); // The user is previewing a comment prior to submitting it. if ($op == t('Preview')) { if (user_access('post comments')) { $build['comment_form'] = comment_add($node, $pid); } else { drupal_set_message(t('You are not authorized to post comments.'), 'error'); drupal_goto("node/$node->nid"); } } else { // $pid indicates that this is a reply to a comment. if ($pid) { if (user_access('access comments')) { // Load the parent comment. $comment = comment_load($pid); if ($comment->status->value == COMMENT_PUBLISHED) { // If that comment exists, make sure that the current comment and the // parent comment both belong to the same parent node. if ($comment->nid->target_id != $node->nid) { // Attempting to reply to a comment not belonging to the current nid. drupal_set_message(t('The comment you are replying to does not exist.'), 'error'); drupal_goto("node/$node->nid"); } // Display the parent comment $build['comment_parent'] = comment_view($comment); } else { drupal_set_message(t('The comment you are replying to does not exist.'), 'error'); drupal_goto("node/$node->nid"); } } else { drupal_set_message(t('You are not authorized to view comments.'), 'error'); drupal_goto("node/$node->nid"); } } // This is the case where the comment is in response to a node. Display the node. elseif (user_access('access content')) { $build['comment_node'] = node_view($node); } // Should we show the reply box? if ($node->comment != COMMENT_NODE_OPEN) { drupal_set_message(t("This discussion is closed: you can't post new comments."), 'error'); drupal_goto("node/$node->nid"); } elseif (user_access('post comments')) { $build['comment_form'] = comment_add($node, $pid); } else { drupal_set_message(t('You are not authorized to post comments.'), 'error'); drupal_goto("node/$node->nid"); } } return $build; } /** * Page callback: Publishes the specified comment. * * @param \Drupal\comment\Plugin\Core\Entity\Comment $comment * A comment entity. * * @see comment_menu() */ function comment_approve(Comment $comment) { // @todo CSRF tokens are validated in page callbacks rather than access // callbacks, because access callbacks are also invoked during menu link // generation. Add token support to routing: http://drupal.org/node/755584. $token = drupal_container()->get('request')->query->get('token'); if (!isset($token) || !drupal_valid_token($token, 'comment/' . $comment->id() . '/approve')) { throw new AccessDeniedHttpException(); } $comment->status->value = COMMENT_PUBLISHED; $comment->save(); drupal_set_message(t('Comment approved.')); drupal_goto('node/' . $comment->nid->target_id); }