Checks current page for specified comment.
Drupal\comment\Comment $comment: The comment object.
boolean $reply: Boolean indicating whether the comment is a reply to another comment.
boolean Boolean indicating whether the comment was found.
function commentExists(Comment $comment = NULL, $reply = FALSE) {
if ($comment) {
$regex = '/' . ($reply ? '<div class="indented">(.*?)' : '');
$regex .= '<a id="comment-' . $comment
->id() . '"(.*?)';
// Comment anchor.
$regex .= $comment->subject->value . '(.*?)';
// Match subject.
$regex .= $comment->comment_body->value . '(.*?)';
// Match comment.
$regex .= '/s';
return (bool) preg_match($regex, $this
->drupalGetContent());
}
else {
return FALSE;
}
}