You are here

function cleantalk_comment_presave in Anti Spam by CleanTalk 8

Same name and namespace in other branches
  1. 8.4 cleantalk.module \cleantalk_comment_presave()
  2. 8.3 cleantalk.module \cleantalk_comment_presave()
  3. 7.5 cleantalk.module \cleantalk_comment_presave()
  4. 7 cleantalk.module \cleantalk_comment_presave()
  5. 7.2 cleantalk.module \cleantalk_comment_presave()
  6. 7.4 cleantalk.module \cleantalk_comment_presave()
  7. 9.1.x cleantalk.module \cleantalk_comment_presave()

Implements hook_comment_presave().

File

./cleantalk.module, line 429
Main CleanTalk integration module functions.

Code

function cleantalk_comment_presave(\Drupal\comment\CommentInterface $comment) {
  $ct_result = _cleantalk_ct_result();
  if (!empty($ct_result['ct_request_id'])) {
    $ct_automod = \Drupal::config('cleantalk.settings')
      ->get('cleantalk_automod');
    if ($ct_automod == 1) {

      // Automoderation enabled - change comment status.
      // Not empty 'ct_result_comment' means bad comment, set status = 0.
      // Empty 'ct_result_comment' means good comment, set status = 1.
      $comment
        ->setPublished(empty($ct_result['ct_result_comment']) ? COMMENT_PUBLISHED : 0);
    }

    // Don't clear 'ct_request_id', use it in cleantalk_comment_insert().
  }
}